title: Consuming messages from Azure Service bus in multiple processes
body: <p>I'm developing a system based on Azure Service Bus for quick fire-and-forget through an API and async processing of a lot of messages by background services through a topic. In the context of this question, the topic has a single subscription, why it could have been a queue. For other reasons, I would like to keep this as a topic.</p>
  
  <p>I recently migrated the code from .NET framework app using the <code>WindowsAzure.ServiceBus</code> package to a .NET Core package using the <code>Microsoft.Azure.ServiceBus</code> package. To process a large number of message, I'm using the <code>MessageReceiver</code> class like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>var connString = "...";
  var subscriptionPath = EntityNameHelper.FormatSubscriptionPath("topic", "subscription");
  var messageReceiver = new MessageReceiver(connString, subscriptionPath);
  while (...)
  {
      var messages = await messageReceiver.ReceiveAsync(10, TimeSpan.FromSeconds(5));
      ...
  }
  </code></pre>
  
  <p>For simplicity, I have hidden a range of details. Like the fact that my app starts 5 threads and process messages in each thread using the same <code>messageReceiver</code> instance.</p>
  
  <p>I normally have more than one instance of this app running to spread out both across threads and processes. And I believe we have finally arrived at the code of my question. After migrating to .NET Core and the new NuGet package, I noticed that only one of the apps is processing messages at the same time. When opening two console windows and launching a process in each window, I can see the app in window 1 starts processing. App in windows 2 doesn't process anything. After a number of seconds, the app in windows 1 stops processing and the app in window 2 starts processing. After a while, it switches back. There's no real pattern in the switch, but all of my messages are successfully processed.</p>
  
  <p>Is there some kind of limitation in <code>MessageReceiver</code> that allows a total maximum number of threads process messages from the same subscription or something like that?</p>