Reputation: 389
I create a windows forms program listening on an Azure Service Bus queue and it executes a long process for each received brokeredMessage :
QueueClient Client = QueueClient.CreateFromConnectionString(ConfigurationWrapper.QueueConnectionString, ConfigurationWrapper.QueueName);
// Configure the callback options
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromMinutes(1);
// Callback to handle received messages
Client.OnMessageAsync((message) =>
{
message.Complete();
//big jobs put 10 minutes
Task t = Task.Factory.StartNew(() => DoAVeryLongJob(message));
return t;
}, options);
If I send 2 messages with 2 seconds of interval in this queue, the program process the first message (calling DoAVeryLongJob which takes 10 minutes) and the second message will be processed at the end of the the first call (10 minutes after). What I want is for these messages to be processed in parallel.
Is it possible to process queue messages in parallel?
Upvotes: 1
Views: 1960
Reputation: 11246
In your OnMessageOptions instance you need to increase your MaxConcurrentCalls. The following code would process 5 messages from the queue in parallel.
// Configure the callback options
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.MaxConcurrentCalls = 5;
options.AutoRenewTimeout = TimeSpan.FromMinutes(1);
Upvotes: 4