5

I using node-amqp with Node.js to consume messages off a queue. Our admins have a 60 minute idle connection timeout, which causes an additional queue to be bound and orphan the previous channels for my queue that were created previously. My logs look as follows and notice how an additional queue is bound every hour (next time will be 3, then 4 and so on):

[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...

Here's how I have my connection and queue configured (notice the events queueUnbindOk and basicCancel aren't being called on idle timeout but instead an connection error even occurs:

 // 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.');
        });
    });

Do you have any suggestions how I can properly configure my connection to gracefully handle the idle timeout?

occasl
  • 5,303
  • 5
  • 56
  • 81
  • 2
    have you tried using heartbeats? Search for heartbeats here: https://www.rabbitmq.com/reliability.html – old_sound Aug 11 '14 at 13:13
  • Yup, that's what I ended up doing. I just set the heartbeat on the connection to a time less than the idle connection timeout and that keeps it open. It doesn't explain my original issue but it does prevent it from happening. – occasl Aug 11 '14 at 20:19

0 Answers0