title: RabbitMQ Queue Not Consumed Parallely By Multiple COnsumer Services
body: <p>I am working on a NodeJS &amp; RabbitMQ where -</p>
  <ul>
  <li>A Master NodeJS Service (one instance) Pushes the data in a queue.</li>
  <li>Slave NodeJS Services (multiple instances) consume the data and process it.</li>
  <li>Default exchange is being used.</li>
  </ul>
  <p>The slave service is running in PM2 Cluster Mode, which means I have got 8 instances for the slave service running.</p>
  <p>My expectation was, as the master service starts pushing in data through the queue, The slave services should start consuming them asynchronously.</p>
  <p>As an example, if master service is pushing 10 jobs through the queue and if each job is taking 5 seconds to complete, it takes slaves 50 seconds to finish the job.</p>
  <p>This is completely defeating the purpose of using multiple slaves as I would nomaly want slaves to pick up 8 jobs at a time.</p>
  <p>As per the RabbitMQ dashboard, above setup creates -</p>
  <ul>
  <li>9 connections ( 1 master + 8 slaves )</li>
  <li>9 channels (1 master + 8 slaves )</li>
  <li>1 queue</li>
  </ul>
  <p>The whole setup uses default exchange.</p>
  <p>My question is -</p>
  <p><strong>Why are the slaves not able to read data from the queue asynchronously?</strong></p>
  <p><strong>Even is I set <code>noAck</code> to <code>true</code> the next item in the queue will not get picked up until curent item is processed</strong></p>
  <p>My intention is to scale up the queue consumption rate by user multiple slave instances but I think I am missing something here.</p>
  <p>Here's the codebase -</p>
  <pre><code>const rabbitMq = require(&quot;amqplib&quot;);
  
  class RabbitMQClient {
  
      async connect() {
          this.connection = await rabbitMq.connect(&quot;amqp://admin:password@localhost&quot;);
          this.channel = await this.connection.createChannel();
          await this.channel.assertQueue(&quot;TEST_QUEUE&quot;);
      }
  }
  
  
  // MASTER CODE (This Runs In Fork Mode - 1 Instance)
  const master_client = new RabbitMQClient();
  master_client.connect().then(() =&gt; {
      // sending in 10 messages
      for (let index = 1; index &lt;= 10; index++) {
          const data = Buffer.from(index.toString(), &quot;utf8&quot;);
          master_client.channel.sendToQueue(&quot;TEST_QUEUE&quot;, data);
      }
  });
  
  
  // SLAVE CODE (This Runs In Cluster Mode - 8 Instances)
  const slave_client = new RabbitMQClient();
  // connect to rabbitmq
  slave_client.connect().then(() =&gt; {
      // consume the messages
      slave_client.channel.consume(&quot;TEST_QUEUE&quot;, (data) =&gt; {
          // timeout to add delay
          setTimeout(() =&gt; {
              RabbitMQClient._channel.ack(data);
          }, 5000);
      });
  });
  </code></pre>
  <p>The slave output -</p>
  <pre><code>33|slave | 2020-11-02 13:19:09.293 +00:00: recieved message - 1  (13-19-09)
  34|slave | 2020-11-02 13:19:14.293 +00:00: recieved message - 2  (13-19-14)
  35|slave | 2020-11-02 13:19:19.299 +00:00: recieved message - 3  (13-19-19)
  36|slave | 2020-11-02 13:19:24.299 +00:00: recieved message - 4  (13-19-24)
  37|slave | 2020-11-02 13:19:29.300 +00:00: recieved message - 5  (13-19-29)
  38|slave | 2020-11-02 13:19:34.299 +00:00: recieved message - 6  (13-19-34)
  39|slave | 2020-11-02 13:19:39.301 +00:00: recieved message - 7  (13-19-39)
  40|slave | 2020-11-02 13:19:44.301 +00:00: recieved message - 8  (13-19-44)
  33|slave | 2020-11-02 13:19:49.299 +00:00: recieved message - 9  (13-19-49)
  34|slave | 2020-11-02 13:19:54.300 +00:00: recieved message - 10 (13-19-54)
  </code></pre>
  <p>If you notice, different slaves are picking up the messages in round-robin fashion but they are working synchronously.</p>
  <p>Thanks!</p>