jwalton / node-amqp-connection-manager

Auto-reconnect and round robin support for amqplib.
527 stars 104 forks source link

channel not reconnected #14

Open sinoohe opened 7 years ago

sinoohe commented 7 years ago

Hi, I wrote a code that the channel is not reconnected! I think something is wrong! I start the script and after 5 seconds I restart the rabbitmq, as a result the nodejs code doesn't continue and pauses!

var amqp = require('amqp-connection-manager'),
    async=require('async');

// Create a new connection manager
var connection = amqp.connect(['amqp://localhost']);

var channelWrapper = connection.createChannel({
  setup: function(channel) {
    // `channel` here is a regular amqplib `ConfirmChannel`.
    return channel.assertQueue('mysample', {durable: true});
  }
});
var i=0;
async.whilst(()=>{return true;},(callback)=>{
  i++;
  console.log('start:'+i);
  channelWrapper.sendToQueue('mysample', new Buffer(JSON.stringify({num:10})))
    .then(function(res) {
      callback();
      return console.log('Message was sent!  Hooray!'+i,res);
    }).catch(function(err) {
      callback();
      return console.log('Message was rejected...  Boo!'+i,err);
    });

});
genetique-techno commented 7 years ago

I ran your code as written and it worked perfectly. Can't reproduce.

LynxyssCZ commented 6 years ago

I ran into this issues as well. Important part for reproduction seems to be not being able to reconnect on the first try. We reproduced this by taking down the broker for more than one heartbeat period and then started it up again.

LynxyssCZ commented 6 years ago

Upon further inspection, it does try to reconnect and eventually succeeds, but takes a long time (default socket timeout + reconnectTimeInSeconds) between tries. Passing shorter and more reasonable timeout through options.connectionOptions fixed our main issue with long reconnects.