forked from postwait/node-amqp
/
test-json.js
59 lines (45 loc) · 1.7 KB
/
test-json.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
52
53
54
55
56
57
58
59
require('./harness');
var recvCount = 0;
var body = "hello world";
connection.addListener('ready', function () {
puts("connected to " + connection.serverProperties.product);
var exchange = connection.exchange('node-json-fanout', {type: 'fanout'});
var q = connection.queue('node-json-queue', function() {
var origMessage1 = {two:2, one:1},
origMessage2 = {foo:'bar', hello: 'world'},
origMessage3 = {coffee:'caf\u00E9', tea: 'th\u00E9'};
q.bind(exchange, "*");
q.subscribe(function (json, headers, deliveryInfo) {
recvCount++;
assert.equal("node-json-fanout", deliveryInfo.exchange);
assert.equal("node-json-queue", deliveryInfo.queue);
assert.equal(false, deliveryInfo.redelivered);
switch (deliveryInfo.routingKey) {
case 'message.json1':
assert.deepEqual(origMessage1, json);
break;
case 'message.json2':
assert.deepEqual(origMessage2, json);
break;
case 'message.json3':
assert.deepEqual(origMessage3, json);
break;
default:
throw new Error('unexpected routing key: ' + deliveryInfo.routingKey);
}
})
.addCallback(function () {
puts("publishing 3 json messages");
exchange.publish('message.json1', origMessage1);
exchange.publish('message.json2', origMessage2, {contentType: 'application/json'});
exchange.publish('message.json3', origMessage3, {contentType: 'application/json'});
setTimeout(function () {
// wait one second to receive the message, then quit
connection.end();
}, 1000);
})
});
});
process.addListener('exit', function () {
assert.equal(3, recvCount);
});