amqplib
amqplib copied to clipboard
Rewrite code examples for readability purposes
The following file: https://github.com/squaremo/amqp.node/blob/master/examples/tutorials/receive_logs.js is complicated for what it does. The code can be improved for readability reasons.
The same code below is less lines and more readable.
function logMessage(msg) {
console.log(" [x] '%s'", msg.content.toString());
}
amqp
.then(async (conn) => {
process.once('SIGINT', () => { conn.close(); });
const channel = await conn.createChannel();
await channel.assertExchange('logs', 'fanout', { durable: false });
const qok = await channel.assertQueue('', { exclusive: true });
await channel.bindQueue(qok.queue, 'logs', '');
await channel.consume(qok.queue, logMessage, { noAck: true });
})
.catch(console.warn);
This applies to all examples.
Given the stated compatibility in the README and travis.yml, an example using await would probably need to be separate.
Done