const amqp = require('amqplib/callback_api'); amqp.connect('amqp://127.0.0.1', (err, connection) => { if (err) { throw err; } connection.createChannel((err, channel) => { if (err) { throw err; } const exchange = 'logs'; const queue = 'consumer1_queue'; channel.assertExchange(exchange, 'fanout', { durable: false }); channel.assertQueue(queue, { durable: false }, (err, q) => { if (err) { throw err; } console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue); channel.bindQueue(q.queue, exchange, ''); channel.consume(q.queue, (msg) => { if (msg.content) { console.log(" [x] Received %s", msg.content.toString()); setTimeout(() => { console.log(" [x] Done processing %s", msg.content.toString()); }, 3000); } }, { noAck: true }); }); }); });