Azure Storage Queue and multiple WebJobs instances: will QueueTrigger set the message lease time on triggered?
Asked Answered
D

2

5

Scenario: producer send a message into the Storage Queue, a WebJobs process the message on QueueTrigger, each message must only be processed once, there could be multiple WebJob instances.

I've been googling and from what I've read, I need to write the function that processes the message to be idempotent so a message isn't processed twice. I've also read that there is a default lease time of 10 minutes for a message.

My question is, when the QueueTrigger is triggered on one WebJob instance, does it set the lease time on the message so that another WebJob can't pick up the same message? If so why do I need to account for the possibility that the message can be processed twice? Or am I misunderstanding this?

Demy answered 6/8, 2015 at 17:33 Comment(0)
M
4

If you are using the built-in queue trigger attributes, it will automatically ensure that any given message gets processed once, even when a site scales out to multiple instances. This is posted on the article in the discussion section, https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/

In the same article you will find clarification regarding the 10 minute lease. In summary, the QueueTrigger attribute directs the WebJobs SDK to call a method when a new message is received in queue. The message is processed and when the method completes, the queue message is deleted. If the method fails before completing, the queue message is not deleted; after a 10-minute lease expires, the message is released to be picked up again and processed. This sequence won't be repeated indefinitely if a message always causes an exception. After 5 unsuccessful attempts to process a message, the message is moved to the poison queue. The maximum number of attempts is configurable.

Mildredmildrid answered 7/8, 2015 at 17:48 Comment(1)
Sorry, this is kind of old answer, but does this also apply to Azure Functions? I have read so many places that when visibility expires the message is visible in the queue again even though the function is still processing. I am confused, because the default visibility timeout is 00:00:00. I have a question here: #55758123Galvin
L
3

Your process need to be idempotent. Because

Facts:

  • A webjob leases a message (No other webjob can get it).
  • A webjob deletes a message when its job is done.
  • If a webjob crashes while processing a message, its lease will time out and another webjob will get and start to process that. (default retry is 5 for a messsage, after that it goes to poison queue)

So if a webjob crashes after its job is done but before it deletes the message, then the message will be released after a while and the same job will be done again.

Therefore your process need to be idempotent.

Latifundium answered 15/2, 2016 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.