title: Nodejs and amqplib: Can't prefetch more than one message
body: <p>So, i'm trying to learn how to create a rabbitmq consumer in node.js. I have been following the tutorials in rabbitmq website.</p>
  
  <p>I'm working with queues and I wanted to fetch more than 1 message at a time. I tried passing 5 to <code>ch.prefetch</code>, but it still only fetches one message per consume call.</p>
  
  <p>The code i'm using is:</p>
  
  <pre><code>var amqp = require('amqplib');
  
  amqp.connect('amqp://localhost').then(function(conn) {
    process.once('SIGINT', function() { conn.close(); });
    return conn.createChannel().then(function(ch) {
      var ok = ch.assertQueue('task_queue', {durable: true});
      ok = ok.then(function() { ch.prefetch(5); });
      ok = ok.then(function() {
        ch.consume('task_queue', doWork, {noAck: false});
        console.log(" [*] Waiting for messages. To exit press CTRL+C");
      });
      return ok;
  
      function doWork(msg) {
        var body = msg.content.toString();
        console.log(" [x] Received '%s'", body);
        var secs = body.split('.').length - 1;
        //console.log(" [x] Task takes %d seconds", secs);
        setTimeout(function() {
          console.log(" [x] Done");
          ch.ack(msg);
        }, secs * 1000);
      }
    });
  }).then(null, console.warn);
  </code></pre>
  
  <p>From this example <a href="https://github.com/squaremo/amqp.node/blob/master/examples/tutorials/worker.js" rel="nofollow">here</a>.</p>
  
  <p>Am I missing something? Why isn't it retrieving more than 1 message at a time?</p>
  
  <p>Thanks</p>