Skip to content

Conversation

Copy link

Copilot AI commented Oct 21, 2025

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:

  • Message 1 starts processing (takes 60 seconds)
  • Message 2 starts processing immediately (takes 10 seconds)
  • Message 2 completes before Message 1
  • Processing order: 2, 1 (incorrect - should be 1, 2)

Root Cause

In subscription.go, the ReceiveBlocking method always launched message handlers in a new goroutine:

// Handle the messages in background
go s.handleAsync(ctx, msgs, handler, receiver)

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 enableInOrderMessageDelivery that controls message processing behavior:

  • When false (default): Maintains current behavior - messages are processed in parallel using goroutines
  • When true: Processes messages synchronously - ensures sequential processing within a session
if s.enableInOrderMessageDelivery {
    s.handleAsync(ctx, msgs, handler, receiver)
} else {
    go s.handleAsync(ctx, msgs, handler, receiver)
}

Usage

To enable in-order message delivery for sessions, add the following to your component metadata:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: servicebus-pubsub
spec:
  type: pubsub.azure.servicebus.topics
  version: v1
  metadata:
    - name: connectionString
      value: "Endpoint=sb://..."
    - name: consumerID
      value: "my-consumer"
    - name: enableInOrderMessageDelivery
      value: "true"

Changes

  • Added EnableInOrderMessageDelivery field to Metadata struct in common/component/azure/servicebus
  • Updated Subscription struct and SubscriptionOptions to include the new flag
  • Modified ReceiveBlocking to conditionally spawn goroutines based on the flag
  • Updated both topics and queues pubsub components to pass the flag through
  • Added metadata documentation in both topics/metadata.yaml and queues/metadata.yaml
  • Added unit tests for the new functionality

Backward Compatibility

This change is fully backward compatible:

  • Default value is false, maintaining existing parallel processing behavior
  • Users must explicitly opt-in by setting enableInOrderMessageDelivery: true
  • No changes required to existing configurations

Testing

  • ✅ All existing unit tests pass
  • ✅ New unit tests added for metadata flag parsing
  • ✅ Linting passes with no issues
  • ✅ Builds successfully

Related Issues

Original prompt

fix this dapr#3868


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: creepycoder <975863+creepycoder@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue 3868 with component configuration Add enableInOrderMessageDelivery flag to fix Azure Service Bus session concurrency issue Oct 21, 2025
Copilot AI requested a review from creepycoder October 21, 2025 07:11
Copilot finished work on behalf of creepycoder October 21, 2025 07:11
@creepycoder creepycoder marked this pull request as ready for review October 26, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Messages with the same session ID are sent in parallel to client app (azure servicebus topic pub-sub)

2 participants