BrighterCommand / BrighterCommand/Brighter

[ASB] Surface broker SequenceNumber in message header bag

Open
#4,142 1 comment 0 reactions 0 assignees View on GitHub
.NET 3 - Done feature request V10.X
Dominant language
C#
Stars
2.5k
Forks
296
Avg merge
1d 11h
Merged PRs (30d)
21

Description

**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](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messages-payloads): *"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."*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.