0

In which order does QueueClient.Receive() deliver messages? I have been running some tests and what I can see a few of the messages (top-most ones I guess) are delivered over and over again if you don't Complete() them. Is there a way to force it deliver in a Round Robin manner?

Gökhan Kurt
  • 531
  • 5
  • 13

2 Answers2

2

When you have a message that is delivered, but not completed, it's expected for message to show up on the queue once LockDuration expires and be consumed again. You have to complete the message. If you don't, it will eventually go into DLQ, but prior to that your consumer(s) will receive it multiple times.

QueueClient.Receive gets whatever is available on the broker (server). I'm not following Round Robin delivery idea, because it's a queue. You get what's in the queue. As a rule of thumb, I would suggest not to rely on the order of messages.

Saying that, there's an ASB Session feature that can preserve and guarantee an ordered of delivery. In case you're looking for sessions, similar question was asked before.

Community
  • 1
  • 1
Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • About the guarantee for ordered delivery , how can this work if the client does not call complete on the message and it pops up again? I guess that there is no guarantee in this case – Maayan Hope May 31 '18 at 05:26
  • If message is not completed, it will be redelivered. I'd say this is not ordering issue. – Sean Feldman May 31 '18 at 05:32
0

When you create the QueueClient you can specify the receive mode and set it to ReceiveAndDelete:

QueueClient.CreateFromConnectionString(connectionString, path, ReceiveMode.ReceiveAndDelete);

This will enable you to remove the message from the queue as soon as you receive it instead of having to call Complete.

If you don't call Complete or use ReceiveAndDelete, the order will be:

  • Get a message (locking it for X seconds)
  • Get the next message in order (locking it for X seconds)
  • First message lock expired so you get it again and relock it.
  • Same for the second message and so on forever.
Stefano d'Antonio
  • 5,874
  • 3
  • 32
  • 45
  • Then it will get some number of messages from the top over and over again. But how many of them? – Gökhan Kurt Oct 10 '16 at 09:04
  • @GökhanKurt not sure I understand your question. – Stefano d'Antonio Oct 10 '16 at 09:10
  • What I understand from the answer it will lock a few of the top most ones and lock them (2 in your example). Then when the lock is expired it will try those two again. Assuming 2 items is just an example how many will it lock and try? Or will it just lock the top most one and wait until lock expires? Or it maybe tries every item from top until the lock expires for the top most one where it begins all over again. – Gökhan Kurt Oct 10 '16 at 11:24
  • 1
    I see now; It will lock in sequence all the messages in the queue top-bottom. Once the lock expires, the next message you get is the oldest locked. – Stefano d'Antonio Oct 10 '16 at 11:29
  • There should then be some default expiration time somewhere. Where you can say how long it will lock each message. – Gökhan Kurt Oct 10 '16 at 11:31
  • Yes, I think you can set it on the queue itself. – Stefano d'Antonio Oct 10 '16 at 11:32