Why "close" event when something goes wrong with node-amqp?

926 views Asked by At

(I am using node-amqp and rabbitmq server.)

I am trying to guess why I have a close event if something goes wrong. For example, If I try to open a a connection to a queue (with bad parameters) I receive an error event. That it is perfect ok.

But, after any error I will receive also a close connection (in that case, maybe because close the failed socket to the queue). And after that, auto-reconnect and I receive the (initial) ready event.

The problem:

connection.on('ready', function() {
 do_a_lot_of_things

}).on(error, function(error){
 solve_the_problem
});

if something goes wrong, I receive the error, but then "ready" event and it will re do_a_lot_of_things. Is my approach wrong?

best regards

1

There are 1 answers

2
Paul Mougel On

You can use connection.once('ready', function () { … }) (see the documentation), which will execute the handler only on the first event.