Skip to content

Instantly share code, notes, and snippets.

@klogic
Created March 29, 2020 23:52
Show Gist options
  • Save klogic/6203f83dd20b28af747dfbec46cd3ca5 to your computer and use it in GitHub Desktop.
Save klogic/6203f83dd20b28af747dfbec46cd3ca5 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) {
if (err) {
console.log("error", err);
} else {
const url = "https://jsonplaceholder.typicode.com";
conn.createChannel(function(err, ch) {
for (let postIndex = 1; postIndex < 15; postIndex++) {
const ex = "posts";
const msg = `${url}/posts/${postIndex}`;
ch.assertExchange(ex, "fanout", { durable: false });
ch.publish(ex, "", new Buffer(msg));
console.log(" [x] Sent %s", msg);
}
});
setTimeout(function() {
conn.close();
process.exit(0);
}, 500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment