Pregunta

I have basic script to take amqp messages and forward them to socket.io It works for hours, sometimes for days, but eventually it silently stops forwarding amqp messages while continuing to emit heartbeats.

Logs show that when it gets to the broken state, it isn't trying to emit socket.io messages as amqp messages arrive, so I think the problem is with amqp connection/subscription rather than socket.io

I tested manually shutting down and restarting the rabbitmq server while the script is running, and it appeared to have no issues reconnecting and continuing to function as it should.

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");
}
¿Fue útil?

Solución

This is a bug in the amqp library: https://github.com/postwait/node-amqp/issues/306

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top