Skip to content

Instantly share code, notes, and snippets.

@RafaelGSS
Created September 2, 2019 00:29
Show Gist options
  • Save RafaelGSS/b9db53f10a171ee92158d42f1902de20 to your computer and use it in GitHub Desktop.
Save RafaelGSS/b9db53f10a171ee92158d42f1902de20 to your computer and use it in GitHub Desktop.
Communication between microservices - RabbitMQ - Producer
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