axk
axk

Reputation: 5394

Does ServiceBusProcessor use thread pool

The question is about ServiceBusProcessor from Azure.Messaging.ServiceBus v7.1.1 used with .NET 5

When I do this

var processor = client1.CreateProcessor("queueName", 
    new ServiceBusProcessorOptions { MaxConcurrentCalls = 3 });
processor.ProcessMessageAsync += ProcessMessageAsync;
await processor.StopProcessingAsync();

I assume it would all run in 1 thread unless I explicitly create Tasks in the thread pool in ProcessMessageAsync?
(Could run 3 concurrent calls if the other 2 calls get blocked by IO and release the thread)

Is this correct?

Upvotes: 0

Views: 948

Answers (1)

Jesse Squire
Jesse Squire

Reputation: 7780

The processor runs a set of background tasks to receive messages, each working independently. In your example, because MaxConcurrentCalls is 3, you'll have 3 tasks running concurrently.

Each task will invoke your ProcessMessageAsync handler, which means that your handler is also being executed concurrently. Unless you're using a shared resource or explicitly synchronizing your handler calls, blocking on one handler invocation will not block the others.

Upvotes: 3

Related Questions