|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -var amqp = require('amqplib/callback_api'); |
| 3 | +const amqp = require('amqplib'); |
4 | 4 |
|
5 | | -var args = process.argv.slice(2); |
| 5 | +const args = process.argv.slice(2); |
6 | 6 |
|
7 | 7 | if (args.length == 0) { |
8 | 8 | console.log("Usage: receive_logs_direct.js [info] [warning] [error]"); |
9 | 9 | process.exit(1); |
10 | 10 | } |
11 | 11 |
|
12 | | -amqp.connect('amqp://localhost', function(error0, connection) { |
13 | | - if (error0) { |
14 | | - throw error0; |
15 | | - } |
16 | | - connection.createChannel(function(error1, channel) { |
17 | | - if (error1) { |
18 | | - throw error1; |
19 | | - } |
20 | | - var exchange = 'direct_logs'; |
21 | | - |
22 | | - channel.assertExchange(exchange, 'direct', { |
23 | | - durable: false |
24 | | - }); |
25 | | - |
26 | | - channel.assertQueue('', { |
27 | | - exclusive: true |
28 | | - }, function(error2, q) { |
29 | | - if (error2) { |
30 | | - throw error2; |
31 | | - } |
32 | | - console.log(' [*] Waiting for logs. To exit press CTRL+C'); |
33 | | - |
34 | | - args.forEach(function(severity) { |
35 | | - channel.bindQueue(q.queue, exchange, severity); |
36 | | - }); |
37 | | - |
38 | | - channel.consume(q.queue, function(msg) { |
39 | | - console.log(" [x] %s: '%s'", msg.fields.routingKey, msg.content.toString()); |
40 | | - }, { |
41 | | - noAck: true |
42 | | - }); |
43 | | - }); |
| 12 | +async function main() { |
| 13 | + const connection = await amqp.connect('amqp://localhost'); |
| 14 | + const channel = await connection.createChannel(); |
| 15 | + |
| 16 | + const exchange = 'direct_logs'; |
| 17 | + |
| 18 | + await channel.assertExchange(exchange, 'direct', { |
| 19 | + durable: false |
| 20 | + }); |
| 21 | + |
| 22 | + const q = await channel.assertQueue('', { |
| 23 | + exclusive: true |
| 24 | + }); |
| 25 | + console.log(' [*] Waiting for logs. To exit press CTRL+C'); |
| 26 | + |
| 27 | + args.forEach(function(severity) { |
| 28 | + channel.bindQueue(q.queue, exchange, severity); |
| 29 | + }); |
| 30 | + |
| 31 | + channel.consume(q.queue, function(msg) { |
| 32 | + console.log(" [x] %s: '%s'", msg.fields.routingKey, msg.content.toString()); |
| 33 | + }, { |
| 34 | + noAck: true |
44 | 35 | }); |
45 | | -}); |
| 36 | +} |
| 37 | + |
| 38 | +main(); |
0 commit comments