Skip to content

Instantly share code, notes, and snippets.

@klogic
Created March 30, 2020 22:22
Show Gist options
  • Save klogic/96789823951197a6e2fd9806f56f3439 to your computer and use it in GitHub Desktop.
Save klogic/96789823951197a6e2fd9806f56f3439 to your computer and use it in GitHub Desktop.
require("dotenv").config();
const amqp = require("amqplib/callback_api");
amqp.connect("amqp://" + process.env.RABBITMQ_URL, function(err, conn) {
conn.createChannel(function(err, ch) {
var ex = "posts";
ch.assertExchange(ex, "fanout", { durable: false });
ch.assertQueue("", { exclusive: true }, function(err, q) {
console.log(
" [*] Waiting for messages in %s. To exit press CTRL+C",
q.queue
);
ch.bindQueue(q.queue, ex, "");
ch.consume(q.queue, function(msg) {
ch.ack(msg);
console.log(" [x] %s", msg.content.toString());
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment