Skip to content

[ASB] Surface broker SequenceNumber in message header bag #4142

Description

@MikeFreeman-Flagstone

Is your feature request related to a problem? Please describe.
When consuming Azure Service Bus messages via Brighter, the broker-assigned SequenceNumber is not surfaced to the consuming application. This makes it difficult to uniquely correlate received messages in application logs, traces, or duplicate-detection logic, since the only identifier available in the message header bag is the LockToken (which is a transient peek-lock reference, not a stable message identity).

Describe the solution you'd like
Add SequenceNumber to the Brighter message header bag when mapping an inbound Azure Service Bus message in AzureServiceBusMesssageCreator.MapToBrighterMessage(), following the same pattern already used for LockToken:

  1. Add long SequenceNumber { get; } to IBrokeredMessageWrapper
  2. Implement it in BrokeredMessageWrapper: public long SequenceNumber => _brokeredMessage.SequenceNumber;
  3. Add public const string SequenceNumberBagKey = "SequenceNumber"; to ASBConstants
  4. In MapToBrighterMessage(), add: headers.Bag.Add(ASBConstants.SequenceNumberBagKey, azureServiceBusMessage.SequenceNumber);

Consuming handlers can then read it via message.Header.Bag["SequenceNumber"].

Describe alternatives you've considered
Using MessageId to uniquely identify a Service Bus message. However, MessageId is application-defined — it is a free-form string set by the sender and is only enforced as unique if duplicate detection is explicitly enabled on the entity. It is not natively assigned or guaranteed by the broker. By contrast, the SequenceNumber is broker-assigned, read-only, and per the Microsoft documentation "functions as the message's true identifier" — a unique 64-bit integer that is monotonically increasing and gapless.

Additional context
From the Microsoft Service Bus documentation: "The sequence number is a unique 64-bit integer assigned to a message as the broker accepts and stores it. It functions as the message's true identifier."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions