Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Webjobs automatically renew leases on Azure Queue messages?

When Webjobs get a message from a queue on Azure Storage via QueueTrigger, it leases the message (makes it invisible). If the triggering function (of webjob) takes a long time to process the message, is this lease automatically extended? Or should I handle that in the function?

On this link Windows Azure Queues: Improved Leases, Progress Tracking, and Scheduling of Future Work, the author states that "A lease on the message can be extended by the worker that did the original dequeue so that it can continue processing the message"

Note: I've tried a webjob (with a QueueTrigger) which waits for 20 minutes.

//Write Log
Thread.Sleep(1200000);
//Write Log

It is completed successfully. And during this time no other webjob instance try to attempt for the same queue item (It did not become visible). Therefore it seems that an auto-renew mechanism for leases exists. Anyhow I am waiting for an answer from a Microsoft employee or with an official link (msdn, azure, ...).

like image 687
Nuri Tasdemir Avatar asked Feb 15 '16 14:02

Nuri Tasdemir


People also ask

What is difference between Webjobs and azure functions?

Webjobs run as background processes in the context of an App Service web app, API app, or mobile app whereas Functions run using a Classic/Dynamic App Service Plan.

What is true about Azure storage queue?

Azure Queue Storage is a service for storing large numbers of messages. You access messages from anywhere in the world via authenticated calls using HTTP or HTTPS. A queue message can be up to 64 KB in size. A queue may contain millions of messages, up to the total capacity limit of a storage account.

How does Azure storage queue work?

Azure Queue storage is a service for storing large numbers of messages that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS. A single queue message can be up to 64 KB in size, and a queue can contain millions of messages, up to the total capacity limit of a storage account.

What is the benefit of using queue in Azure?

Azure Service Bus Queue A key benefit of using queues is to the producers (senders) and consumers (receivers) don't have to send and receive messages at the same time. Furthermore, the producer doesn't have to wait for a reply from the consumer to continue to process and send messages.


1 Answers

Yes, your lease is automatically extended. It is 10 minutes each time.

See this answer here [1] by a Microsoft employee referring to the docs and comments on azure.microsoft.com [2].

EDIT (long answer)

In addition, an examination of the source code, starting with the QueueListener class at https://github.com/Azure/azure-webjobs-sdk/blob/cfc875a7f00e595410c0603e6ca65537025490a9/src/Microsoft.Azure.WebJobs.Host/Queues/Listeners/QueueListener.cs indicates the same.

The code in QueueListener has the relevant parts on line 138, where the 10 minute visibilityTimeout variable is defined:

TimeSpan visibilityTimeout = TimeSpan.FromMinutes(10); // long enough to process the job

That variable is then passed along to ProcessMessageAsync, which starts a timer defined in the method CreateUpdateMessageVisibilityTimer with that same value. The 10 minute value is used to determine when the first and next update the visibility timeout also (by halving it and creating an instance of the LinearSpeedupStrategy class).

Eventually, in the class UpdateQueueMessageVisibilityCommand [3], you will find that the UpdateMessageAsync method on the queue is called with that same 10 minute renewal.

The LinearSpeedupStrategy will renew again after 5 minutes, unless the renewal failed in which case it will try again after 1 minute (as defined in QueueListener).

[1] Azure Storage Queue and multiple WebJobs instances: will QueueTrigger set the message lease time on triggered?

[2] https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/

[3] https://github.com/Azure/azure-webjobs-sdk/blob/cfc875a7f00e595410c0603e6ca65537025490a9/src/Microsoft.Azure.WebJobs.Host/Queues/Listeners/UpdateQueueMessageVisibilityCommand.cs

like image 177
SvenAelterman Avatar answered Oct 09 '22 23:10

SvenAelterman