GH-3533: ASB session-id pinning (5.x backport → 5.40.0) - #3544
Merged
Conversation
…identifiers (5.x backport) Backport of the 6.x change to the 5.0 maintenance line, bumped to 5.40.0. Add an opt-in ServiceBusSessionProcessor-based session listener so competing consumers on ONE shared queue/subscription can each be pinned to their own session id(s). On a shared entity the session id becomes a broker-enforced routing key, so a listener pinned to "A" never sees the messages meant for "B". - ConfigureSessionProcessor(Action<ServiceBusSessionProcessorOptions>) on both queue and subscription listener configs (multicast, so it composes) - RequireSessionsWithOnlyTheseIdentifiers(params string[]) sugar that populates ServiceBusSessionProcessorOptions.SessionIds - BuildSessionProcessorOptions maps ListenerCount -> MaxConcurrentSessions, keeps in-session FIFO, and reserves ReceiveMode=PeekLock / AutoCompleteMessages=false - New InlineAzureServiceBusSessionListener; AzureServiceBusEnvelope gains a ProcessSessionMessageEventArgs complete/defer/dead-letter path Gated: the legacy AcceptNextSession loop stays the default and only flips to the processor when ConfigureSessionProcessor is set, so existing session listeners are unaffected. Adapted to the 5.0 code shape (no ConfigureProcessor / IReportConnectionState / PrefetchCount that exist on 6.x). No conditional compilation needed: the Azure SDK session-processor APIs are available on net8.0/net9.0/net10.0. Unit tests + an emulator end-to-end test reproducing the issue, all green on net9.0; full project builds clean on all three TFMs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FKAxzuZ36VP6UPcTQf3MUs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #3534 (issue #3533) to the
5.0maintenance line. Targets the5.0branch and bumps the version to 5.40.0 for a NuGet release.What
Adds an opt-in
ServiceBusSessionProcessor-based session listener so competing consumers on one shared Azure Service Bus queue/subscription can each be pinned to their own session id(s). On a shared entity the session id becomes a broker-enforced routing key — a listener pinned to"A"never sees the messages meant for"B".Plus the general
ConfigureSessionProcessor(Action<ServiceBusSessionProcessorOptions>)hook (multicast) on both queue and subscription listener configs.Gating / safety
The existing hand-rolled
AcceptNextSessionloop remains the default; the processor engine only engages whenConfigureSessionProcessoris set (directly or viaRequireSessionsWithOnlyTheseIdentifiers). Existing session listeners are untouched. Wolverine reservesReceiveMode = PeekLockandAutoCompleteMessages = false.Backport notes
Adapted to the 5.0 code shape, which differs from 6.x:
ConfigureProcessor, noIReportConnectionState/AzureServiceBusConnectionStateMapper, and no endpointPrefetchCount— so the new listener andBuildSessionProcessorOptionsare written to the leaner 5.0 shape (session processor options carry no prefetch).ServiceBusSessionProcessor,ServiceBusSessionProcessorOptions,CreateSessionProcessor, andProcessSessionMessageEventArgsare all inAzure.Messaging.ServiceBusregardless of target framework. The project builds clean onnet8.0;net9.0;net10.0.Tests
BuildSessionProcessorOptions+ both fluent methods."A"receives exactly its messages; a seeded"B"message stays undelivered on the shared queue).All 8 tests green on net9.0 against the Azure Service Bus emulator; full ASB project builds clean on all three TFMs.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FKAxzuZ36VP6UPcTQf3MUs