amqplib icon indicating copy to clipboard operation
amqplib copied to clipboard

Rewrite code examples for readability purposes

Open basickarl opened this issue 8 years ago • 1 comments

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.

basickarl avatar May 28 '17 14:05 basickarl

Given the stated compatibility in the README and travis.yml, an example using await would probably need to be separate.

connec avatar May 28 '17 16:05 connec

Done

cressie176 avatar Dec 10 '22 01:12 cressie176