0

One can receive messages in azure service bus using either of the the two methods..

queueClient.BeginReceiveBatch OR messageReceiver.ReceiveBatchAsync

Is there any difference between these two methods speedwise or in any other way.

Thanks

Arnab
  • 2,324
  • 6
  • 36
  • 60
  • 1
    Maybe you can find answer here: http://stackoverflow.com/questions/3081079/difference-between-async-and-begin-net-asynchronous-apis – jakobandersen May 18 '15 at 18:43
  • @miracledev Thanks for the link but has anything changed since last 5 years such as with TPL or anything else.. – Arnab May 18 '15 at 19:09

1 Answers1

1

If you don't need to the batch receive functionalilty, I prefer the method of wiring up a callback on the OnMessage event of the queue client. We have some fairly high throughput services relying on this pattern of message processing without any issues (1M+ messages/day)

I like that you end up with less, and simpler code, and can easily control the options of how many messages to process in parallel, which receive mode (peek and lock, vs receive and delete), etc

There's a sample of it in this documentation:

string connectionString =
  CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
QueueClient Client =
  QueueClient.CreateFromConnectionString(connectionString, "TestQueue");

// Configure the callback options
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromMinutes(1);

// Callback to handle received messages
Client.OnMessage((message) =>
{
    try
    {
        // Process message from queue
        Console.WriteLine("Body: " + message.GetBody<string>());
        Console.WriteLine("MessageID: " + message.MessageId);
        Console.WriteLine("Test Property: " +
        message.Properties["TestProperty"]);

        // Remove message from queue
        message.Complete();
    }
        catch (Exception)
    {
        // Indicates a problem, unlock message in queue
        message.Abandon();
    }
};
Veatch
  • 893
  • 7
  • 11
  • The MaxConcurrentCalls property on the OnMessageOptions: https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.onmessageoptions.maxconcurrentcalls.aspx. There's good information on how that property works here: http://stackoverflow.com/questions/18255323/does-azure-servicebus-queueclient-onmessage-execute-on-a-different-thread – Veatch May 19 '15 at 15:56