🐇 RabbitMQ connection string changes

This commit is contained in:
2021-10-21 22:04:58 -07:00
parent 22170c53b3
commit 755ac43820

View File

@@ -1,28 +1,28 @@
import { logger } from "../utils/logger.utils"; import { logger } from "../utils/logger.utils";
//RabbitMQ //RabbitMQ
const amqp = require("amqplib/callback_api"); const amqp = require("amqplib/callback_api");
const rabbitUrl = process.env.DOCKER_RABBITMQ_HOST ? `amqp://${process.env.DOCKER_RABBITMQ_HOST}` : `amqp://localhost`; const rabbitUrl = process.env.DOCKER_RABBITMQ_CONNECTION_STRING ? process.env.DOCKER_RABBITMQ_CONNECTION_STRING : `amqp://localhost`;
export const sendToRabbitMQ = (queueName, data) => { export const sendToRabbitMQ = (queueName, data) => {
// connect to local rabbitmq instance // connect to local rabbitmq instance
amqp.connect(rabbitUrl, (error0, connection) => { amqp.connect(rabbitUrl, (error0, connection) => {
if (error0) { if (error0) {
throw error0; throw error0;
} }
// create channel // create channel
connection.createChannel((error1, channel) => { connection.createChannel((error1, channel) => {
if (error1) { if (error1) {
throw error1; throw error1;
} }
const queue = queueName; const queue = queueName;
// Checks for “queueName (updateStock)” queue. If it doesnt exist, then it creates one. // Checks for “queueName (updateStock)” queue. If it doesnt exist, then it creates one.
channel.assertQueue(queue, { channel.assertQueue(queue, {
durable: false, durable: false,
}); });
channel.sendToQueue(queue, Buffer.from(data)); channel.sendToQueue(queue, Buffer.from(data));
logger.info(`${data} sent`); logger.info(`${data} sent`);
}); });
setTimeout(function() { setTimeout(function () {
connection.close(); connection.close();
// process.exit(0); // process.exit(0);
}, 500); }, 500);