RMQ Consumer (Node.js)

const amqp = require("amqplib");

const connectionParams = {
  hostname: "HostName",
  port: 5672,
  username: "<Username>",
  password: "<Password>",
  vhost: "<VHOST>",
};

const queue = "_Q_";

async function receiveMessage() {
  try {
    const connection = await amqp.connect(connectionParams);
    const channel = await connection.createChannel();

    console.log("Waiting for messages in queue:", queue);
    channel.consume(
      queue,
      function (msg) {
        console.log("Received message:", msg.content.toString());
      },
      {
        noAck: true,
      }
    );
  } catch (error) {
    console.error(error);
  }
}

receiveMessage();

Last updated