2

When a message is retrieved from an azure queue but not deleted from it, the messages visibility timeout expires and the message is (re)added to the end of the queue.

Is there a way to return such messages to the head of the queue instead?

Malt
  • 28,965
  • 9
  • 65
  • 105
  • Not 100% sure I understand your scenario, but if you PeekLock the message, you may be able to avoid it needing to be re-appended to the queue. If the process succeeds, remove the message, otherwise, just remove the lock. – DanielG May 14 '15 at 18:08
  • @DanielG I think you're talking about the azure service bus queues. I mean the regular azure queues: https://azure.microsoft.com/en-in/documentation/articles/storage-dotnet-how-to-use-queues/ – Malt May 14 '15 at 18:11
  • @DanielG although using the service bus queues might actually be a solution.. – Malt May 14 '15 at 18:12
  • Yes Malt, I am more familiar with Service Bus Queues. I think they offer more flexibility in your scenario, but may have a slight performance disadvantage. – DanielG May 14 '15 at 18:21

1 Answers1

2

When Azure Queue messages re-appear, they don't necessarily get sent to the end of the queue. They just reappear, and at that point, no real guarantee of order. It doesn't even get moved from its current position; it's just visible again. Azure storage queues aren't set up for guaranteed order. So no, there's no way to force a message to appear at the head of the queue when it reappears after its invisibility timeout expires.

Also, check out this forum answer from Jai Haridas regarding queue message ordering. Specifically:

The messages in a queue today are sorted by its visibility time. So the ordering of messages purely depends on when they are made visible. However, it is important for an app to not assume FIFO order or any specific order as it may change in future. You can only rely that 1) a message will be eligible based on its visibility timeout and 2) Message processing should be made idempotent and use the new UpdateMessage to save state

UpdateMessage() allows you to modify the queue message (e.g.adding breadcrumbs), so the next time you start processing it, you can pick up at a point beyond "start." Note that you can also adjust the timeout value, while it's still in your possession and invisible, to allow you to keep working on the message.

David Makogon
  • 69,407
  • 21
  • 141
  • 189