-
Notifications
You must be signed in to change notification settings - Fork 2
/
consumer.js
23 lines (17 loc) · 926 Bytes
/
consumer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var amqp = require('amqp');
var connection = amqp.createConnection({url: "amqp://guest:guest@localhost:5672"}, {defaultExchangeName: "test-exchange"});
connection.on('ready', function(){
connection.exchange('test-exchange', {type: 'direct', autoDelete: false, durable: false}, function (exchange) {
console.log('Exchange ' + exchange.name + ' is open');
connection.queue('test-key', function(queue){
queue.bind(exchange, 'test-key');
queue.on('queueBindOk', function() {
console.log(' [*] Waiting for messages. To exit press CTRL+C')
queue.subscribe(function(msg, headers, deliveryInfo){
console.log(" [x] Received %s", msg.data.toString('utf-8'));
console.log('Got a message with routing key ' + deliveryInfo.routingKey);
});
});
});
});
});