Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

Understading Execution Model - Threading

$
0
0

Hi All

I've been developing a proof of concept application using Azure Service Bus for a customer. It's working as expected so far, but I have some issues understanding how to make it scale.

Lets take the following code, which is a modified versión of the one created with an Azure Sevice Worker Role Project:

        public override void Run()
        {
            Trace.WriteLine("Starting processing of messages");

            //Initiates the message pump and callback is invoked for each message that is received, calling close on the client will stop the pump.
            hotelAddRequestClient.OnMessage((receivedMessage) =>
                {
                    try
                    {
                        // Process the message
                        Trace.WriteLine("Processing Service Bus message: " + receivedMessage.SequenceNumber.ToString());
                        ProcessHotelAddRequest(receivedMessage);
                    }
                    catch(Exception ex)
                    {
                        Trace.Write("Exception catched processing message");
                        // Handle any message processing specific exceptions here
                    }
                });

            CompletedEvent.WaitOne();
        }

Its quite simple: register the event to execute for every message, wait until the application stops. hotelAddRequestClient is a QueueClient.

Now the questions:

  • How many threads are executing this code?
  • Does every QueueClient create its own thread for processing of its incoming messages?
  • Do I need to create a thread pool (every thread with its QueueClient object) if I want to be able to process more tan 1 message concurrently, or is the runtime automatically doing the job for me?
  • Whats the difference between using OnMessage and OnMessageAsync events, if there is only 1 thread executing the code?

I'm an old school developer and used to create threads or thread pools to parallelize processes. Here, I cant see where are the threads that are procesing the messages.

Best  regards

Miquel



Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>