-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (30 loc) · 958 Bytes
/
server.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
'use strict';
const timers = require('timers');
const createWarren = require('warren');
const brokerConfig = {
vhosts: { '/': { exchanges: ['e'], queues: ['q'], bindings: [ 'e -> q' ] } },
publications: { p: { exchange: 'e' } },
subscriptions: { s: { queue: 'q' } },
}
const hosts = [5672, 5673].map(port => ({ hostname: '192.168.99.100', port }));
const options = {
hosts,
brokerConfig,
timeout: 1000,
minBrokersAvailable: 1
};
const warren = createWarren(options, (err, warren) => {
if(err) return console.log(err);
warren.subscribe('s', (message, content, ackOrNack) => {
console.log(`received message: ${content}`);
ackOrNack()
});
function publish(count) {
warren.publish('p', count, {}, err => {
console.log(`publish confirmed: ${count} ${err ? err.message : ''}`);
timers.setTimeout(publish, 500, count + 1);
});
}
publish(1);
});
warren.on('error', err => console.log(`${err.message}`));