Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Error using Azure Service Bus Subscription OnMessageAsync event

$
0
0

We are using Azure Service Bus in our project and while reading messages from service bus topic/subscription. We are using ‘subscriptionClient.OnMessageAsync’ event in conjunction with ‘onMessageOptions.ExceptionReceived’. Let me write down the steps we followed to reproduce the issue we are facing.

  1. Create a service bus namespace with default config in the azure portal
  2. Create a topic inside it with default config in the azure portal
  3. Create a subscription inside it with default config in the azure portal
  4. Create a console app and paste the code added below
  5. Connect the service bus using Service Bus Explorer
  6. Run the console app
  7. Send a few test messages from service bus explorer & watch the console app window
  8. Though the messages are processed successfully every time the control is going inside the ‘ExceptionReceived’ method
class Program {
   static void Main()
   {
        var subscriptionClient =    SubscriptionClient.CreateFromConnectionString( servicebusendpointaddress", "topicname", subscriptionname", ReceiveMode.PeekLock);
        var onMessageOptions = new OnMessageOptions();
        onMessageOptions.ExceptionReceived += OnMessageError;
        subscriptionClient.OnMessageAsync(OnMessageReceived, onMessageOptions);
        Console.ReadKey();
    }

    private static void OnMessageError(object sender, ExceptionReceivedEventArgs e)
    {
        if (e != null && e.Exception != null)
        {
            Console.WriteLine("Hey, there's an error!" + e.Exception.Message + "\r\n\r\n");
        }
    }

    private static async Task OnMessageReceived(BrokeredMessage arg)
    {
        await arg.CompleteAsync();
        Console.WriteLine("Message processing done!");
    }
}

Message processing done!
Hey, there's an error!The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. TrackingId:dd011e
d7-1037-4f1e-912b-c0c605eec60a_G1_B13,TimeStamp:5/18/2015 1:55:02 PM


Message processing done!
Hey, there's an error!The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue. TrackingId:2d3aaf
a4-a6cc-48f3-bd85-63e476daef1b_G1_B13,TimeStamp:5/18/2015 1:55:04 PM

Are we missing something here?

Also one point to mention is that is we enable ‘autocomplete’ and remove the ‘await arg.CompleteAsync();’ then this is not happening.

var onMessageOptions = new OnMessageOptions() { AutoComplete = true};

In both the cases the messages are being processed successfully & removed from the subscription immediately.



Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>