Add enableInOrderMessageDelivery flag to fix Azure Service Bus session concurrency issue #1
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.
Overview
Fixes dapr#3868 - Messages with the same session ID were being processed in parallel instead of sequentially when using Azure Service Bus with sessions enabled, breaking the ordering guarantees that sessions provide.
Problem
When using Azure Service Bus topics with sessions enabled (
requireSessions: true), messages with the same Session ID were being sent to the client application in parallel. This violated the fundamental guarantee of Service Bus sessions: that messages within the same session should be processed in the order they were sent.The issue manifested as:
Root Cause
In
subscription.go, theReceiveBlockingmethod always launched message handlers in a new goroutine:This meant that multiple messages from the same session could be processed concurrently, defeating the purpose of sessions.
Solution
Following the same pattern as the EventHub fix in PR dapr#3605, this PR adds a new optional configuration flag
enableInOrderMessageDeliverythat controls message processing behavior:false(default): Maintains current behavior - messages are processed in parallel using goroutinestrue: Processes messages synchronously - ensures sequential processing within a sessionUsage
To enable in-order message delivery for sessions, add the following to your component metadata:
Changes
EnableInOrderMessageDeliveryfield toMetadatastruct incommon/component/azure/servicebusSubscriptionstruct andSubscriptionOptionsto include the new flagReceiveBlockingto conditionally spawn goroutines based on the flagtopics/metadata.yamlandqueues/metadata.yamlBackward Compatibility
This change is fully backward compatible:
false, maintaining existing parallel processing behaviorenableInOrderMessageDelivery: trueTesting
Related Issues
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.