β

Read ECONNRESET comes up when amqp restarts

User zangw - Stack Overflow 218 阅读

Currently I create one Sender class client which can send messages to amqp, and also reconnect to amqp. When messages need to be sent to amqp, if the connection is failed, Sender can try to reconnect to amqp three time. Here are the codes https://gist.github.com/richzw/e39237aa1fe31c15a587

Then I test it with following codes,

var Sender = require('./sender.js');
var amqpAddress = 'amqp://localhost';
var sender = new Sender( amqpAddress, 2000, 3, sendMessageCallback );
function sendMessageCallback( ) {
    console.error('Message can NOT be sent due to MessageBus error');
}
// send message every 5 seconds
var CronJob = require('cron').CronJob;
var send_message_job = new CronJob({
    cronTime: '*/5 * * * * *',
    onTick: function(){
         sender.deliverMessage( key, msg );
    },
    start: true,
});
send_message_job.start();

Then I try to stop and start amqp service randomly. I find when I restart amqp service at the first time, the sender can continue to send messages normally. However, when I try to stop the service at the second time, the following error comes up, and the program is crashed.

Error: read ECONNRESET at errnoException (net.js:905:11) at TCP.onread (net.js:559:19)

I try to test it several times with the same scenario, the above error always comes up at the second time. Why? Can anyone help me figure out how to handle it?

作者:User zangw - Stack Overflow
most recent 30 from stackoverflow.com
原文地址:Read ECONNRESET comes up when amqp restarts, 感谢原作者分享。

发表评论