我使用带有Node.js的node-amqp来消耗队列中的消息。我们的管理员有60分钟的空闲连接超时,这会导致绑定一个额外的队列并孤立我之前创建的队列的先前通道。我的日志如下所示,并注意每小时如何绑定一个额外的队列(下一次将是3,然后是4,依此类推):
[app] 2014-08-07T16:15:25.000Z: 2014-08-07T16:15:25.174Z - debug: ConsumerTag: node-amqp-145-0.9590792271774262
[app] 2014-08-07T16:15:24.000Z: 2014-08-07T16:15:24.751Z - debug: AMQP Queue bound successfully.
[app] 2014-08-07T16:15:24.000Z: 2014-08-07T16:15:24.731Z - debug: AMQP Queue bound successfully.
[app] 2014-08-07T16:15:24.000Z: 2014-08-07T16:15:24.344Z - debug: AMQP Queue is subscribing...
[app] 2014-08-07T16:15:24.000Z: 2014-08-07T16:15:24.344Z - debug: AMQP Queue is binding...
[app] 2014-08-07T16:15:23.000Z: 2014-08-07T16:15:23.831Z - debug: AMQP Queue is initializing...
[app] 2014-08-07T15:13:36.000Z: 2014-08-07T15:13:36.933Z - debug: ConsumerTag: node-amqp-145-0.6444592161569744
[app] 2014-08-07T15:13:36.000Z: 2014-08-07T15:13:36.658Z - debug: AMQP Queue bound successfully.
[app] 2014-08-07T15:13:36.000Z: 2014-08-07T15:13:36.341Z - debug: AMQP Queue is subscribing...
[app] 2014-08-07T15:13:36.000Z: 2014-08-07T15:13:36.341Z - debug: AMQP Queue is binding...
[app] 2014-08-07T15:13:36.000Z: 2014-08-07T15:13:36.067Z - debug: AMQP Queue is initializing...
以下是我如何配置连接和队列(注意事件queueUnbindOk
和basicCancel
在空闲超时时没有被调用,而是发生连接错误:< / p>
// Establish connection to AMQP
var conn = amqp.createConnection({url: amqp_url, clientProperties: { applicationName: "ma-services", capabilities: { consumer_cancel_notify: true }}});
conn.on('ready', function () {
logger.debug('AMQP Queue is initializing...');
var ctag;
var queue = conn.queue('ma.services.gapns', {'durable': true, 'autoDelete': false}, function (queue) {
try {
logger.debug('AMQP Queue is binding...');
queue.bind('ma.integration.exchange', 'gapns');
logger.debug('AMQP Queue is subscribing...');
queue.subscribe( function (msg) {
// do stuff
}).addCallback(function(ok) {
logger.debug("ConsumerTag: " + ok.consumerTag);
ctag = ok.consumerTag;
});
}
catch (e) {
logger.error("Exception occurred while processing notifications: " + e);
}
});
queue.on('queueBindOk', function () {
logger.debug('AMQP Queue bound successfully.');
});
queue.on('basicCancel', function() {
// this never gets called
logger.debug('The channel has been canceled (likely server timeout).');
});
queue.on('queueUnbindOk', function () {
// Unsubscribe from queue to prevent orphan -- never gets called
logger.debug('Unsubscribing consumertag: ' + ctag);
queue.unsubscribe(ctag);
logger.debug('AMQP Queue unbound successfully.');
});
});
您是否有任何建议我如何正确配置我的连接以优雅地处理空闲超时?