Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Queue unique message

I would like to make sure that I don't insert a message to the queue multiple times. Is there any ID/Name I can use to enforce uniqueness?

like image 833
Philip Avatar asked May 26 '11 06:05

Philip


People also ask

What information uniquely identifies a queue?

Queue identity The Identity parameter uses the basic syntax <Server>\ <Queue>. Typically, this value uniquely identifies the queue, so you can't use other filtering parameters with the Identity parameter.

What is Azure queue message?

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.

What is the difference between Azure storage queue and Azure Service Bus queue?

Storage queues provide a uniform and consistent programming model across queues, tables, and BLOBs – both for developers and for operations teams. Service Bus queues provide support for local transactions in the context of a single queue.


2 Answers

vtortola pretty much covered it, but I wanted to add a bit more detail into why it's at least once delivery.

When you read a queue item, it's not removed from the queue; instead, it becomes invisible but stays in the queue. That invisibility period defaults to 30 seconds (max: 2 hours). During that time, the code that got the item off the queue has that much time to process whatever command was in the queue message and delete the queue item.

Assuming the queue item is deleted before the timeout period is reached, all is well. However: Once the timeout period is reached, the queue item becomes visible again, and the code holding the queue item may no longer delete it. In this case, someone else can read the same queue message and re-process that message.

Because of the fact a queue message can timeout, and can re-appear:

  • Your queue processing must be idempotent - operations on a queue message must result in the same outcome (such as rendering a thumbnail for a photo).
  • You need to think about timeout adjustments. You might find that commands are valid but processing is taking too long (maybe your 45-second thumbnail rendering code worked just fine until someone uploaded a 25MP image)
  • You need to think about poison messages - those that will never process correctly. Maybe they cause an exception to be thrown or have some invalid condition that causes the message processor to abort processing, which leads to the message eventually re-appearing in the queue. There's a property callded DequeueCount - consider viewing that property upon reading a queue item and, if equal to, say, 3, push the message into a table or blob and send yourself a notification to spend some time debugging that message offline.

More details on the get-queue low-level REST API is here. This will give you more insight into Windows Azure queue message handling.

like image 143
David Makogon Avatar answered Oct 05 '22 09:10

David Makogon


Azure queues doesn't ensure message order and either message uniqueness. Messages will be processed "at least once", but nothing ensures it won't be processed twice, so it doesn't ensure "at most once".

You should get ready to receive the same message twice. You can put an ID in the body of the message as part of your data.

like image 31
vtortola Avatar answered Oct 05 '22 07:10

vtortola