azure-docs
azure-docs copied to clipboard
Message sequence number and enqueued time in exceptional scenarios
I would like some explanation on what happens to the sequence number when a message is abandoned or when a message is processed and the consumer throws an exception or the consumer is killed. Are they going to stay the same or updated? What happens in session based messaging?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 034f7b39-4f6b-87c4-5dfa-a09ea0235b6e
- Version Independent ID: 6987bbec-c4e9-573f-89c5-aa316af045f9
- Content: Azure Service Bus message sequencing and timestamps - Azure Service Bus
- Content Source: articles/service-bus-messaging/message-sequencing.md
- Service: service-bus-messaging
- GitHub Login: @spelluru
- Microsoft Alias: spelluru
@adeliab Thanks for reaching out. The sequence number will only be changed once the message state changes to Active from scheduled state as documented. For any other scenario there is no change to the sequence number.
The SequenceNumber for a scheduled message is only valid while the message is in this state. As the message transitions to the active state, the message is appended to the queue as if had been enqueued at the current instant, which includes assigning a new SequenceNumber.
when a message is abandoned or when a message is processed and the consumer throws an exception or the consumer is killed. Are they going to stay the same or updated? What happens in session based messaging? SequenceNumber remains the same if your consumer abandoned the message/throws any exception then only the delivery count on the message increases by one every time your client is not able to consume that message. When you Deferred the message then you should be using the SequenceNumber to retrieve the deferred message.
Feel free to get back to me if you have any further queries or concerns.
@adeliab Just following up here. Hope my previous comment clears things up.
@MayankBargali-MSFT thanks for the clarification. So in terms of 'normal' (non scheduled messages), the sequence number stays the same. Only in the scenario of scheduled messages, the sequence number gets updated when a message changes state from scheduled to active. Am I understanding it correctly?
@adeliab Yes, your understanding is correct.
We will now proceed to close this thread. If there are further questions regarding this matter, please reopen it and we will gladly continue the discussion.