Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid race condition in Windows Azure Queue

We have a Queue and multiple instances of same worker role reading the messages from the queue. The processing of each message is very fast. How do we avoid a case where two instances try to read same message from the queue at exact same point of time.

like image 745
kishore Avatar asked Jan 11 '23 00:01

kishore


1 Answers

You are not going to have any problems with multiple clients accessing an Azure Storage Queue simultaneously, provided you follow a Read-and-Delete pattern:

The message is not automatically deleted from the queue, but after it has been retrieved, it is not visible to other clients for the time interval specified by the visibilitytimeout parameter.

Source: http://msdn.microsoft.com/en-us/library/windowsazure/dd179474.aspx

The nature of queues requires that every operation on the head of the queue must be atomic. In the case of queues as services, if it were possible for multiple clients to perform concurrent operations which caused overlapped reads, the queue would be utterly unusable.

like image 175
Paul Turner Avatar answered Jan 19 '23 10:01

Paul Turner