DAS_2024_1/bondarenko_max_lab_4/consumer1.js

41 lines
982 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 = 'queue1';
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()}'`);
setTimeout(() => {
console.log(` [x] Done processing '${msg.content.toString()}'`);
}, 2000);
}, {
noAck: true,
});
});
});
});