-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
798870d
commit b6f6df4
Showing
6 changed files
with
323 additions
and
215 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
const amqp = require('amqplib/callback_api'); | ||
const amqp = require('amqplib'); | ||
|
||
const CONN_URL = 'amqps://hsmwnpfw:[email protected]/hsmwnpfw'; | ||
let ch = null; | ||
amqp.connect(CONN_URL, function(err, conn){ | ||
conn.createChannel(function(err, channel){ | ||
ch = channel; | ||
}) | ||
}) | ||
const CONN_URL = process.env.CLOUDAMQP_URL; | ||
|
||
const publishToQueue = async (queueName, data) => { | ||
ch.sendToQueue(queueName, new Buffer.from(data)); | ||
} | ||
(async () => { | ||
try { | ||
const connection = await amqp.connect(CONN_URL); | ||
const channel = await connection.createChannel(); | ||
|
||
process.on('exit', (code) =>{ | ||
ch.close(); | ||
console.log('Closing rabbitmq channel'); | ||
}); | ||
const publishToQueue = (queueName, data) => { | ||
const message = Buffer.from(data); | ||
channel.sendToQueue(queueName, message); | ||
}; | ||
|
||
module.exports = {publishToQueue} | ||
process.on('beforeExit', async (code) => { | ||
await channel.close(); | ||
console.log('Closing RabbitMQ channel'); | ||
}); | ||
|
||
module.exports = { publishToQueue }; | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} | ||
})(); |
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.