Ajit Soutadekar Thanks for reaching here!
Based on the information provided, it seems like the first message picked up by the WebJob takes longer to process than the subsequent messages.
This could be due to the Storage Queue going into idle mode.
One solution to handle this idle time in the Storage Queue is to increase the visibility timeout of the messages.
To explain-
Azure Storage Queue does not provide Ordering guarantees. However, Storage bus queue is able to provide First In First Out (FIFO) capabilities by using message sessions.
Please check this document that compares both the queues: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-azure-and-service-bus-queues-compared-contrasted
Messages in Storage Queues are typically first-in-first-out, but sometimes they can be out of order.
For example, when the visibility-timeout duration of a message expires because a client application crashed while processing a message. When the visibility timeout expires, the message becomes visible again on the queue for another worker to dequeue it. At that point, the newly visible message might be placed in the queue to be dequeued again.
By default, the visibility timeout is set to 30 seconds, which means that if a message is picked up by a WebJob and not deleted within 30 seconds, it becomes visible to other clients.
You can increase the visibility timeout to a higher value, such as 2-3 minutes, to give the WebJob enough time to process the message before it becomes visible to other clients. This can be done by setting the visibilityTimeout
property when calling the receiveMessage
method in your WebJob code.
Another solution is to use the updateMessage
method to periodically update the message's visibility timeout while it is being processed by the WebJob. This will prevent the message from becoming visible to other clients while it is still being processed.
See- Below links might be helpful
- https://learn.microsoft.com/en-us/azure/storage/queues/storage-quickstart-queues-dotnet?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli#receive-messages-from-a-queue
- https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.webjobs.host.queuesoptions.visibilitytimeout?view=azure-dotnet
- https://learn.microsoft.com/en-us/rest/api/storageservices/put-message I hope this helps! Let me know if you have any further questions.