Last active
September 13, 2019 15:55
-
-
Save gate3/9ba272aa9557be1d87911746299b7da7 to your computer and use it in GitHub Desktop.
Sending Realtime Events To The Client From Node child process
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 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