Aaron Hoffman
Aaron Hoffman

Reputation: 6962

Azure WebJob Process Storage Queue Messages Serially

We have a need to process messages from an Azure Storage Queue serially, one at a time.

By default, the JobHostConfiguration.Queues.BatchSize is set to 16

https://github.com/Azure/azure-webjobs-sdk/blob/0581fb1610d56a597523fcea67733944efba9541/src/Microsoft.Azure.WebJobs.Host/JobHostQueuesConfiguration.cs#L15

And those 16 messages the WebJob pulls off the queue will be processed in parallel. Instead, we need the WebJob to process the messages serially, one at a time.

How can this be achieved?

We are currently forced to set the BatchSize to 1, which is not ideal because it introduces a lot of spin up/down time around reading from the message queue.

Clarification: We do not need to enforce first in first out, or guaranteed order processing, just one at a time processing.

Upvotes: 1

Views: 1282

Answers (1)

vivek kv
vivek kv

Reputation: 416

JobHostConfiguration config = new JobHostConfiguration();
config.Queues.BatchSize = 1;
config.Queues.MaxDequeueCount = 1;
config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(5);

Set your BatchSize and MaxDequeueCount to 1, Set MaxPollingInterval to 5 seconds.

Upvotes: 2

Related Questions