ServiceBus Processor - Dont concurrently process messages for the same session

77 views Asked by At

I want to process sessions concurrently. However, within each session, I want to process only one message at a time.

   ServiceBusProcessorClient processorClient = new ServiceBusClientBuilder()
            .credential(new DefaultAzureCredentialBuilder().build())
            .fullyQualifiedNamespace(InsightsServiceSBEndPoint)
            .sessionProcessor()
            .queueName(SuccesQueue)
            .maxConcurrentSessions(5)
            .maxConcurrentCalls(5)

With the above setting, the processor processes multiple sessions concurrently as intended. But say if I send 3 messages for session id#1, I see all the 3 messages being processed concurrently. I want these 3 messages to be processed one after the other (otherwise there is no benefit of using sessions)

What am I missing?

1

There are 1 answers

5
Sean Feldman On

There are 2 important processor configurations that impact session based processing.

  1. MaxConcurrentSessions - the maximum number of sessions that can be processed concurrently by a function.
  2. MaxConcurrentCallsPerSession - the maximum number of concurrent calls to the function per session. Thus the total number of concurrent calls will be equal to MaxConcurrentSessions X MaxConcurrentCallsPerSession.

The maxConcurrentCalls is not for sessions processing but for non sessions enabled entities. To achieve what you need, the code would be

   .sessionProcessor()
   .queueName(SuccesQueue)
   .maxConcurrentSessions(5)
   .maxConcurrentCallsPerSession(1) // the default should be 1 but depends on the SDK