title: Processing Messages in Parallel in Azure Service Bus
body: <p>Problem: I've got tons of emails to send, presently, an average of 10 emails in the queue at any point in time. The code I have process the queue one at a time; that is, receive the message, process it and eventually send the email. This cause a considerably delay in sending emails to users when they signup for the service.</p>
  
  <p>I've begun to think of modifying the code to <code>process the messages in parrallel</code> say 5 asynchronously. I'm imagining writing a method and using the <code>CTP</code> to call this method in parallel, say, 5 times.</p>
  
  <p>I'm a little bit lost in how to implement this. The cost of making a mistake is exceedingly great as users will get disappointed if things go wrong. </p>
  
  <p><code>Request:</code> I need help in writing code that process messages in Azure service bus in parallel.
  Thanks.</p>
  
  <pre><code>My code in a nutshell.
  
  Public .. Run()
  {
     _myQueueClient.BeginReceive(ProcessUrgentEmails, _myQueueClient);
  }
  
  void ProcessUrgentEmails(IAsyncResult result)
  {
     //casted the `result` as a QueueClient
     //Used EndReceive on an object of BrokeredMessage
     //I processed the message, then called
     sendEmail.BeginComplete(ProcessEndComplete, sendEmail);
   }
  
  
   //This method is never called despite having it as callback function above.
   void ProcessEndComplete(IAsyncResult result)
   {
       Trace.WriteLine("ENTERED ProcessEndComplete method...");
       var bm = result.AsyncState as BrokeredMessage;
       bm.EndComplete(result); 
   }
  </code></pre>