1
我有基本腳本可以接收amqp消息並將它們轉發到socket.io 它可以持續工作數小時,有時甚至幾天,但最終會靜默地停止轉發amqp消息,同時繼續發出心跳。nodejs + amqp默默死亡
日誌顯示,當它到達斷狀態,它是不是想爲AMQP郵件到達時發出socket.io的消息,所以我覺得這個問題是AMQP連接/訂閱而不是socket.io
我在腳本運行時手動關閉並重新啓動rabbitmq服務器,似乎沒有任何問題重新連接並繼續按照它的功能運行。
var port = 8888,
http = require("http"),
amqp = require("amqp"),
socketio = require("socket.io"),
express = require("express"),
rabbitMq = amqp.createConnection({ host: 'server', reconnect: true }),
app = express(),
server = http.createServer(app),
io = socketio.listen(server);
rabbitMq.on("ready", function() {
console.log("ready");
var queue = rabbitMq.queue("ft-secondary-display", function() {
queue.bind(rabbitMq.exchange('ft', {type: 'topic'}), "data");
console.log("bound");
queue.subscribe(function (message, headers, basicInfo) {
var data = {'key': basicInfo, 'data': message.data.toString()};
io.sockets.emit("message-name", data);
});
});
});
setInterval(hb, 10000);
function hb(){
io.sockets.emit("message-name", "heartbeat");
}