沈斌
2017-02-16 c42f063280a776458e2a36d8e80fe393a75bf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * Created by bin.shen on 16/02/2017.
 */
 
var config = require("./config");
var amqp = require('amqplib/callback_api');
 
amqp.connect(config.rabbitmq.uri, function(err, conn) {
    conn.createChannel(function(err, ch) {
        ch.assertExchange(config.rabbitmq.ex, 'fanout', {durable: false});
        ch.assertQueue('', {exclusive: true}, function(err, q) {
            console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q.queue);
            ch.bindQueue(q.queue, config.rabbitmq.ex, '');
            ch.consume(q.queue, function(msg) {
                console.log(" [x] %s", msg.content.toString());
            }, {noAck: true});
        });
    });
});