5

ワーカーの 1 つで、一定時間後にメッセージを受信したいと考えています。いわゆるデッドレター交換を発見した後、Node と RabbitMQ を使用することにしました。

メッセージは DeadExchange のキューに送信されたように見えますが、コンシューマは WorkExchange の WorkQueue で時間が経過してもメッセージを受信して​​いません。bindQueue がオフになっているか、デッドレターが機能していませんか?

私は今、多くの異なる値を試しました。誰かが私が欠けているものを指摘できますか?

var amqp = require('amqplib');
var url = 'amqp://dev.rabbitmq.com';

amqp.connect(url).then(function(conn) {
    //Subscribe to the WorkQueue in WorkExchange to which the "delayed" messages get dead-letter'ed (is that a verb?) to.
    return conn.createChannel().then(function(ch) {
        return ch.assertExchange('WorkExchange', 'direct').then(function() {
            return ch.assertQueue('WorkQueue', {
                autoDelete: false,
                durable: true
            })
        }).then(function() {
            return ch.bindQueue('WorkQueue', 'WorkExchange', '');
        }).then(function() {
            console.log('Waiting for consume.');

            return ch.consume('WorkQueue', function(msg) {
                console.log('Received message.');
                console.log(msg.content.toString());
                ch.ack(msg);
            });
        });
    })
}).then(function() {
    //Now send a test message to DeadExchange to a random (unique) queue.
    return amqp.connect(url).then(function(conn) {
        return conn.createChannel();
    }).then(function(ch) {
        return ch.assertExchange('DeadExchange', 'direct').then(function() {
            return ch.assertQueue('', {
                arguments: {
                    'x-dead-letter-exchange': 'WorkExchange',
                    'x-message-ttl': 2000,
                    'x-expires': 10000
                }
            })
        }).then(function(ok) {
            console.log('Sending delayed message');

            return ch.sendToQueue(ok.queue, new Buffer(':)'));
        });
    })
}).then(null, function(error) {
    console.log('error\'ed')
    console.log(error);
    console.log(error.stack);
});

npm の amqplib であるamqp.node ( https://github.com/squaremo/amqp.node ) を使用しています。node-amqp ( https://github.com/postwait/node-amqp ) の方がはるかに人気があるようですが、完全なプロトコルを実装しておらず、再接続に関して未解決の問題がかなりあります。

dev.rabbitmq.com は RabbitMQ 3.1.3 を実行しています。

4

3 に答える 3