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:
- I have created a settings.job file with {"is_singleton": true} property in it.
- I have also tried using [Singleton] attribute on top of the function signature.
- I tried setting the properties config.Queues.BatchSize = 1 and config.Queues.NewBatchThreshold = 1.
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.
Figured it out. The settings I need is ServiceBusConfiguration.MessageOptions.MaxConcurrentCalls = 1. It can be done like so:
Thanks to this post: Azure WebJob concurrency when using ServiceBusTrigger for the example.