37 lines
835 B
JavaScript
37 lines
835 B
JavaScript
|
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,
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|