-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht2-direct-consumer.js
39 lines (28 loc) · 1.12 KB
/
t2-direct-consumer.js
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
33
34
35
36
37
38
39
var amqp = require('amqplib');
var args = process.argv.slice(2);
var severity = args[0] || 'info';
amqp.connect('amqp://localhost').then(function(conn) {
process.once('SIGINT', function() { conn.close(); });
return conn.createChannel().then(function(ch) {
var ex = 'direct_logs';
var ok = ch.assertExchange(ex, 'direct', {durable: false});
ok = ok.then(function() {
return ch.assertQueue('', {exclusive: true});
});
ok = ok.then(function(qok) {
var queue = qok.queue;
return ch.bindQueue(queue, ex, severity).then(function() { return 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:'%s'",
msg.fields.routingKey,
msg.content.toString());
}
});
}).then(null, console.warn);