-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathproducer.js
47 lines (47 loc) · 1.46 KB
/
producer.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
'use strict';
const bramqp = require('bramqp');
const net = require('net');
const async = require('async');
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.basic.publish(1, 'logs', 'logKey', true, false, function() {
handle.content(1, 'basic', {}, 'basic', function() {
console.log('message published');
seriesCallback();
});
});
}, function(seriesCallback) {
handle.on('1:basic.return', function(replyCode, replyText, exchange, routingKey) {
console.log('Message Returned from Server');
console.log(replyCode);
console.log(replyText);
console.log(exchange);
});
seriesCallback();
}, function(seriesCallback) {
setTimeout(function() {
console.log('close communication');
handle.closeAMQPCommunication(seriesCallback);
}, 10 * 1000);
}, function(seriesCallback) {
console.log('socket ended');
handle.socket.end();
setImmediate(seriesCallback);
}], function(err) {
if (err) {
console.log(err);
}
console.log('all done');
});
});