Does the QueueClient.OnMessage method always execute the callback parameter on a different thread?
I assume that if MaxConcurrentCalls is set to 10 then the queueClient would spin up a maximum of 10 threads to process the messages in parallel. Does a new thread get created if you pass in a MaxConcurrentConnection value of 1 or does it execute back on the current thread?
My actual problem:
Within a Worker Role I would like to handle multiple queues but have them all process concurrently. E.g.
_queueClient1.OnMessage(x =>
{
// Do something
}, new OnMessageOptions { MaxConcurrentCalls = 1});
_queueClient2.OnMessage(x =>
{
// Do something
}, new OnMessageOptions { MaxConcurrentCalls = 1 });
_queueClient3.OnMessage(x =>
{
// Do something
}, new OnMessageOptions { MaxConcurrentCalls = 1 });
_queueClient4.OnMessage(x =>
{
// Do something
}, new OnMessageOptions { MaxConcurrentCalls = 1 });
Would this result in each callback being executed in parallel so that the _queueClient4 callback isn't waiting for _queueClient2 to finish before it can execute?
When you register a callback with OnMessage
it is called on a different thread. If you set MaxConcurrentCalls
to say 10, then we will create 10 threads for 10 messages and callback all of these for each message concurrently. You can do this across Queues too as you show above but of course there is no synchronization or ordering done between each individual callback processing.
When we invoke the callback on a new thread, then it is synchronous for that particular execution/message in that until the method completes or an exception is thrown, the message processing is not completed. If MaxConcurrentCalls
is 0 then only a single thread will be processed for each of the callback registered. However when you have different QueueClient instances you can register different callbacks to them or the same callback with different concurrent counts etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With