Created
March 29, 2020 23:52
-
-
Save klogic/6203f83dd20b28af747dfbec46cd3ca5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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