Skip to content

Instantly share code, notes, and snippets.

@gate3
Last active September 13, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gate3/9ba272aa9557be1d87911746299b7da7 to your computer and use it in GitHub Desktop.
Save gate3/9ba272aa9557be1d87911746299b7da7 to your computer and use it in GitHub Desktop.
Sending Realtime Events To The Client From Node child process
const rabbitMq = require('amqplib');
class RabbitMqHelper {
constructor (channel_name) {
this.channel = null;
this.connection = null;
this.queueAssert = null;
this.channel_name = channel_name
}
async setup () {
const conn = await rabbitMq.connect(process.env.RABBITMQ_URL)
const ch = await conn.createChannel()
this.queueAssert = ch.assertQueue(this.channel_name, {durable:true})
this.channel = ch
return this.queueAssert
}
sendToQueue (message) {
this.channel.sendToQueue(this.channel_name, Buffer.from(message), {persistent: true});
}
}
module.exports = RabbitMqHelper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment