amqp-node / amqplib

AMQP 0-9-1 library and client for Node.JS

Home Page:https://amqp-node.github.io/amqplib/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use channel.consume to set up synchronous consumption?

Dooy opened this issue · comments

commented

The first message has not been processed yet, and the second message comes.

EG...

const processMessage = async message => {
  try {
    console.log(msg.content);
    await sleep(2000);
    console.log("hi");
     channel.ack(message);
  } catch(error) {
     // handle errors
  }
};
const ready = await channel.consume(queueAssertion.queue, processMessage, {
   noAck: false
});

async function sleep(time){
  return new Promise(h=>setTimeout(h,time));
}
commented

sorry , use channel.prefetch(1, true) to achieve the effect