node.jsrabbitmqamqpcloudamqpnode-amqp

Error handling exclusive queue subscription in node-amqp (node.js)


When you subscribe to an exclusive queue (only one consumer allowed at a time), node-amqp throws an exception when the queue is oversubscribed (already has a consumer).

Here's my subscription line, but it's nothing special:

queue.subscribe({ack: true, prefetchCount: 1, exclusive: exclusive}, cbExecute).addCallback((ok) -> listeners[type] = ok.consumerTag);

You get an unhandled exception thrown when queue is in use:

ACCESS_REFUSED - queue 'respQ' in vhost 'brkoacph' in exclusive use

Looking inside node-amqp I see that they implement an independent task queue inside the module so that when the error occurs, the task is running in an independent context.

Is there any work-around/fix? ...or am I just doing something wrong?


Solution

  • I think what you want to do is to catch the errors in the AMQP connection. As you mentioned, node-amqp captures errors in a different context, but you can listen to then on the connection:

    yourConnectionVar.on( 'error', function(err) {
      //do something
      console.log('An error occurred' + err);
    });
    

    I hope this helps.

    Cheers!