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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With