Files
threetwo-core-service/queue/importQueue.ts
2021-09-14 23:13:34 -07:00

31 lines
814 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { logger } from "../utils/logger.utils";
//RabbitMQ
const amqp = require("amqplib/callback_api");
const rabbitUrl = "amqp://localhost";
export const sendRabbitMQ = (queueName, data) => {
// connect to local rabbitmq instance
amqp.connect(rabbitUrl, (error0, connection) => {
if (error0) {
throw error0;
}
// create channel
connection.createChannel((error1, channel) => {
if (error1) {
throw error1;
}
const queue = queueName;
// Checks for “queueName (updateStock)” queue. If it doesnt exist, then it creates one.
channel.assertQueue(queue, {
durable: false,
});
channel.sendToQueue(queue, Buffer.from(data));
logger.info(`${data} sent`);
});
setTimeout(function () {
connection.close();
//process.exit(0);
}, 500);
});
};