DAS_2024_1/bondarenko_max_lab_4/consumer2.js

37 lines
835 B
JavaScript
Raw Normal View History

2024-12-10 21:33:59 +04:00
const amqp = require('amqplib/callback_api');
const EXCHANGE_NAME = 'logs';
const QUEUE_NAME = 'queue2';
amqp.connect('amqp://localhost', (err, connection) => {
if (err) {
throw err;
}
connection.createChannel((err, channel) => {
if (err) {
throw err;
}
channel.assertExchange(EXCHANGE_NAME, 'fanout', {
durable: false,
});
channel.assertQueue(QUEUE_NAME, {
exclusive: false,
}, (err, q) => {
if (err) {
throw err;
}
channel.bindQueue(q.queue, EXCHANGE_NAME, '');
channel.consume(q.queue, (msg) => {
console.log(` [x] Received '${msg.content.toString()}'`);
}, {
noAck: true,
});
});
});
});