-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathconsumer.js
51 lines (51 loc) · 1.76 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const bramqp = require('bramqp');
const net = require('net');
const async = require('async');
let queueName = '';
const socket = net.connect({
port: 5672
});
bramqp.initialize(socket, 'rabbitmq/full/amqp0-9-1.stripped.extended', function(error, handle) {
async.series([function(seriesCallback) {
handle.openAMQPCommunication('guest', 'guest', true, seriesCallback);
}, function(seriesCallback) {
handle.exchange.declare(1, 'logs', 'fanout', false, false, true, false, false, {});
handle.once('1:exchange.declare-ok', function(channel, method, data) {
console.log('exchange declared');
seriesCallback();
});
}, function(seriesCallback) {
handle.queue.declare(1, '', false, false, false, true, false, {});
handle.once('1:queue.declare-ok', function(channel, method, data) {
console.log('queue declared');
queueName = data.queue;
seriesCallback();
});
}, function(seriesCallback) {
handle.queue.bind(1, queueName, 'logs', null, false, {});
handle.once('1:queue.bind-ok', function(channel, method, data) {
console.log('queue bound sucessfully');
seriesCallback();
});
}, function(seriesCallback) {
handle.basic.consume(1, queueName, null, false, true, true, false, {});
handle.once('1:basic.consume-ok', function(channel, method, data) {
console.log('consuming from queue');
console.log(data);
handle.on('1:basic.deliver', function(channel, method, data) {
console.log('incoming message');
console.log(data);
handle.once('content', function(channel, className, properties, content) {
console.log('got a message:');
console.log(content.toString());
console.log('with properties:');
console.log(properties);
seriesCallback();
});
});
});
}], function() {
console.log('all done');
});
});