3
我在最近3天內嘗試了以下問題。請幫我解決問題,AMQP連接關閉與節點js的特定時間間隔
>Error: Unexpected close
at succeed (/usr/local/lib/node_modules/amqplib/lib/connection.js:259:13)
at onOpenOk (/usr/local/lib/node_modules/amqplib/lib/connection.js:241:5)
at /usr/local/lib/node_modules/amqplib/lib/connection.js:160:32
at /usr/local/lib/node_modules/amqplib/lib/connection.js:154:12
at Socket.recv (/usr/local/lib/node_modules/amqplib/lib/connection.js:480:12)
at Socket.g (events.js:180:16)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:407:10)
at emitReadable (_stream_readable.js:403:5)
at readableAddChunk (_stream_readable.js:165:9)
我正在使用amqplib + node js。每當我啓動服務器時,我都有一段時間間隔出現上述錯誤。最大時間間隔爲5分鐘。
amqplib = amqplib.connect('amqp://'+rabit_host).then(function(conn)
{
amqpconnection = conn;
});
io.sockets.on('connection', function(client)
{
client.on('receivemsg', function(arg)
{
amqpconnection.createConfirmChannel().then(function(channelObjSuccess)
{
channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});
client.assignObj = channelObjSuccess;
channelObjSuccess.consume(queue_name, function(msg)
{
var encodemsg = msg.content.toString();
var json_msg = JSON.parse(encodemsg);
client.emit('chatrecive',json_msg);
}).then(function(){
console.log("Receive Consiuume Close");
});
});
});
client.on('loginentry', function(arg)
{
amqpconnection.createConfirmChannel().then(function(channelObjSuccess) {
channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});
});
});
client.on('sendmsg', function(arg)
{
var payload_stringify = JSON.stringify(arg);
amqpconnection.createConfirmChannel().then(function(channelObjSuccess) {
channelObjSuccess.assertQueue(queue_name,{durable:false,autoDelete:true});
channelObjSuccess.sendToQueue(queue_name, new Buffer(payload_stringify), {},
function(err, ok)
{
if (err !== null)
console.log('Message Send Failure! ');
else
{
channelObjSuccess.close();
}
});
});
});
client.on('disconnect', function()
{
try {
console.log("AMPQ Connection Closed - Disconnect");
if(typeof(client.assignObj)!=undefined)
{
client.assignObj.close();
}
}
catch (alreadyClosed) {
console.log("RabbitMQ Connection Already Closed " + alreadyClosed.stackAtStateChange);
}
});
});
server.listen(port);
的錯誤來自您的插座,請張貼相關的代碼。 'self.stream.on('end',self.onSocketError.bind(self,new Error('Unexpected close')));' – xShirase 2014-10-07 05:25:09
感謝您的快速響應。什麼時候會打電話?你想要哪部分代碼? – Prakash 2014-10-07 05:41:43
,說錯誤是一個套接字錯誤,所以告訴我們一些套接字代碼 – xShirase 2014-10-07 05:43:24