Created
March 30, 2020 22:54
-
-
Save klogic/61f1c29a38cc28c671d5416222bbfb02 to your computer and use it in GitHub Desktop.
This file contains 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"); | |
const { getPosts } = require("./firerequest"); | |
amqp.connect("amqp://" + process.env.RABBITMQ_URL, (err, conn) => { | |
conn.createChannel((err, ch) => { | |
var ex = "posts"; | |
ch.assertExchange(ex, "fanout", { durable: false }); | |
ch.assertQueue("", { exclusive: true }, (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, async msg => { | |
ch.ack(msg); | |
const url = msg.content.toString(); | |
const post = await getPosts(url); | |
console.log(post); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment