-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathreceive_logs.js
More file actions
executable file
·32 lines (27 loc) · 899 Bytes
/
receive_logs.js
File metadata and controls
executable file
·32 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
var amqp = require('amqplib');
var conn = amqp.connect('amqp://localhost')
conn.then(createChannel).then(null, console.warn);
function createChannel(conn) {
process.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {
var ok = ch.assertExchange('logs', 'fanout', {durable: false});
ok = ok.then(function() {
return ch.assertQueue('', {exclusive: true});
});
ok = ok.then(function(qok) {
return ch.bindQueue(qok.queue, 'logs', '').then(function() {
return qok.queue;
});
});
ok = ok.then(function(queue) {
return ch.consume(queue, logMessage, {noAck: true});
});
return ok.then(function() {
console.log(' [*] Waiting for logs. To exit press CTRL+C');
});
function logMessage(msg) {
console.log(" [x] '%s'", msg.content.toString());
}
});
}