Reputation: 580
I have an Azure webjob that reads from a Service Bus Queue. My goal is to process 1 message from a Queue, synchronously, per instance. Is that possible?
What I have observed is that if there are 100 messages in the queue, I see 10~20 instances of the webjob running at the same time, each processing different messages from the queue. I would like to limit this to 1 message. I have tried the following so far:
Here's the signature of my webjob function:
[ServiceBusAccount("servicebusconnstr")]
public static void MigrateDoc([ServiceBusTrigger("myqueue")] string queueItem, TextWriter log)
{
...
}
None of these methods seem to work.
Upvotes: 0
Views: 389
Reputation: 580
Figured it out. The settings I need is ServiceBusConfiguration.MessageOptions.MaxConcurrentCalls = 1. It can be done like so:
var config = new JobHostConfiguration();
var serviceBusConfig = new ServiceBusConfiguration();
serviceBusConfig.MessageOptions.MaxConcurrentCalls = 1;
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseServiceBus(serviceBusConfig);
var host = new JobHost(config);
host.RunAndBlock();
Thanks to this post: Azure WebJob concurrency when using ServiceBusTrigger for the example.
Upvotes: 0