forked from postwait/node-amqp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
42 lines (30 loc) · 1.08 KB
/
test.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
var amqp = require('./amqp');
var connection = amqp.createConnection({host: 'localhost'});
connection.addListener('close', function (e) {
if (e) {
throw e;
} else {
console.log('connection closed.');
}
});
connection.addListener('ready', function () {
console.log('connected to ' + connection.serverProperties.product);
var exchange = connection.exchange('clock', {type: 'fanout'});
var q = connection.queue('my-events-receiver');
q.bind(exchange, "*").addCallback(function () {
console.log('publishing message');
exchange.publish('message.json', {hello: 'world', foo: 'bar'});
exchange.publish('message.text', 'hello world', {contentType: 'text/plain'});
});
q.subscribe(function (m) {
console.log('--- Message (' + m.deliveryTag + ", '" + m.routingKey + "') ---");
console.log('--- contentType: ' + m.contentType);
m.addListener('data', function (d) {
console.log(d);
});
m.addListener('end', function () {
m.acknowledge();
console.log('--- END (' + m.deliveryTag + ", '" + m.routingKey + "') ---");
});
});
});