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