title: Get all messages from rabbitMQ
body: <p>I'm trying to get all messages from rabbitMQ queue.</p>
  
  <pre><code>const messages = await rabbit.getMessages(outputQueue, false);
  </code></pre>
  
  <p>Here is realization of getMessages method. The problem is it processes only 3-5 messages and calling 'resolve'. Some time later it processes rest messages, but 'resolve' has already been called and it can't be executed again.</p>
  
  <pre><code>const amqp = require('amqplib');
  .
  .
  let amqpUrl;
  let queueConf;
  
  const init = (connection, queue) =&gt; {
    amqpUrl =`amqp://${connection.user}:${connection.password}@${connection.host}:${connectio    n.port}`;
    if (connection.vhost) {
  amqpUrl = `amqp://${connection.user}:${connection.password}@${connection.host}:${connection.port}/${connection.vhost}`;
    }
    queueConf = queue;
  }
  
  const getChannel = () =&gt; new Promise((resolve) =&gt; {
    amqp.connect(amqpUrl).then((conn) =&gt; {
      conn.createChannel().then((ch) =&gt; {
        ch.prefetch(1000).then(() =&gt; resolve(ch))
      })
    })
  })
  
  module.exports = (connection, queue) =&gt; {
    init(connection, queue);
    return {
      getMessages: (queueName, cleanQueue) =&gt; new Promise((resolve) =&gt; {
        let messages = [];
        let i = 1;
        getChannel().then((ch) =&gt; {
          ch.consume(queueName, (msg) =&gt; {
            messages.push(msg);
            console.log(msg.content.toString())
          }, { noAck: cleanQueue }).then(() =&gt; {
            logger.info(`Retreived ${messages.length} messages from ${queueName}`);
            resolve(messages)
          })
        })
      })
      .
      .
      };
    };
  </code></pre>
  
  <p>Thanks in advance !</p>