forked from Alexey/DAS_2024_1
41 lines
982 B
JavaScript
41 lines
982 B
JavaScript
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,
|
|
});
|
|
});
|
|
});
|
|
});
|