How Peek works in a Partition enabled Service Bus Queue?

Deepak Mohan Singh.P.S 21 Reputation points
2020-10-24T15:46:38.1+00:00

I understand from the docs that during the first Peek() operation, any one of the available message brokers respond and send their oldest message. Then on subsequent Peek() operation, we can traverse across the partitions to peek every message with increased sequence number.

My question is, during the very first Peek() operation, I will get a message from any of the first responded partitions. Is there a guarantee that it's sequence number the lowest across all the partitions?

In a much simpler way, there are three Partitions: Partition "A" has 10 messages with sequence number from 1 to 10. Partition "B" has 10 messages with sequence number from 11 to 20. Partition "C" has 10 messages with sequence number from 21 to 30.

Now if i perform Peek() operation, which Partition will respond first? And secondly, is there a guarantee that repeated QueueClient.Peek() can browse all the messages in a partitioned queue? If I can get the initial response from partition "B" during Peek(), won't I miss out browsing messages from Partition "A" as its sequence numbers are lower compared to "B" which the QueueClient can never visit since it increments sequence number while Peeking?

CC: @Sean Feldman

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
544 questions
0 comments No comments
{count} votes

Accepted answer
  1. ChaitanyaNaykodi-MSFT 22,701 Reputation points Microsoft Employee
    2020-10-29T01:27:34.54+00:00

    Hello @Deepak Mohan Singh.P.S , Sorry for the delay in my response. In partition enabled entities the sequence number assigned is relative to the partition itself, the topmost 16 bits of 64 bit long sequence number are used to uniquely identify a partition and hence no partition is missed, you can find more information here. Now when you perform the peek(), as mentioned in the document it returns the oldest message in one of the partitions whose message broker responded first and there is no guarantee that the returned message is the oldest one across all partitions.
    Regarding browsing all the messages in a partition you can use the QueueClient.PeekBatch method to fetch the messages until the returned messages are null or less then the requested number. You can find more information here.
    Just in case if you want to maintain the FIFO guarantee, you can enable sessions, and use the sessionId as the partition key.
    Please let me know if there are any additional concerns. Thank you!

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful