|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -var amqp = require('amqplib'); |
4 |
| -var conn = amqp.connect('amqp://localhost') |
5 |
| -var ch = conn.then(createChannel).then(null, console.warn); |
| 3 | +var amqp = require('amqplib/callback_api'); |
6 | 4 |
|
7 |
| -ch.then(function(ch) { |
8 |
| - var x = ch.assertExchange('logs', 'fanout', {durable: false}); |
9 |
| - var q = x.then(function() { |
10 |
| - return ch.assertQueue('', {exclusive: true}); |
11 |
| - }); |
| 5 | +amqp.connect('amqp://localhost', function(err, conn) { |
| 6 | + conn.createChannel(function(err, ch) { |
| 7 | + var ex = 'logs'; |
| 8 | + |
| 9 | + ch.assertExchange(ex, 'fanout', {durable: false}); |
12 | 10 |
|
13 |
| - ok = q.then(function(qok) { |
14 |
| - return ch.bindQueue(qok.queue, 'logs', '').then(function() { |
15 |
| - return qok.queue; |
| 11 | + ch.assertQueue('', {exclusive: true}, function(err, q) { |
| 12 | + console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue); |
| 13 | + <
8000
span class=pl-s1>ch.bindQueue(q.queue, ex, ''); |
| 14 | + |
| 15 | + ch.consume(q.queue, function(msg) { |
| 16 | + console.log(" [x] %s", msg.content.toString()); |
| 17 | + }, {noAck: true}); |
16 | 18 | });
|
17 | 19 | });
|
18 |
| - ok = ok.then(function(queue) { |
19 |
| - return ch.consume(queue, logMessage, {noAck: true}); |
20 |
| - }); |
21 |
| - return ok.then(function() { |
22 |
| - console.log(' [*] Waiting for logs. To exit press CTRL+C'); |
23 |
| - }); |
24 |
| - |
25 |
| - function logMessage(msg) { |
26 |
| - console.log(" [x] '%s'", msg.content.toString()); |
27 |
| - } |
28 | 20 | });
|
29 |
| - |
30 |
| -function createChannel(conn) { |
31 |
| - process.once('SIGINT', function() { conn.close(); }); |
32 |
| - return conn.createChannel(); |
33 |
| -} |
0 commit comments