Created
September 2, 2019 00:29
-
-
Save RafaelGSS/b9db53f10a171ee92158d42f1902de20 to your computer and use it in GitHub Desktop.
Communication between microservices - RabbitMQ - Producer
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
const amqp = require('amqplib') | |
async function createConnection (uri = 'guest:guest@localhost:5672') { | |
const connection = await amqp.connect('amqp://' + uri) | |
return connection | |
} | |
createConnection() | |
.then(conn => conn.createChannel()) | |
.then(ch => { | |
console.log('Channel created!') | |
const queue = 'messages' | |
ch.assertQueue(queue) | |
setInterval(() => { | |
console.log('-> Sending message') | |
ch.sendToQueue(queue, Buffer.from('Message of example')) | |
}, 1000) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment