jakobloekke / jakobloekke-rabbitmq

AMQP-client for Meteor.js
6 stars 1 forks source link

RabbitMQ Connection failure causes Meteor Application start-up failure #1

Closed occasl closed 9 years ago

occasl commented 9 years ago

I'm using your plugin in my app. I have it configured to connect to RabbitMQ on Meteor.startup(), however, if the RabbitMQ server isn't available to connect to at the time, it fails with the following error and prevents Meteor from starting up the rest of the application:

    Error: [Error: getaddrinfo ENOTFOUND]
        at Connection.<anonymous> (packages/jakobloekke_rabbitmq/packages/jakobloekke_rabbitmq.js:20:1)
        at Connection.emit (events.js:117:20)
        at CleartextStream.emit (events.js:95:17)
        at Socket.onerror (tls.js:1456:17)
        at Socket.emit (events.js:117:20)
        at net.js:834:16
        at process._tickCallback (node.js:448:13)

Ideally, it would be nice it if just warned of this situation and continued running the Meteor app. I'm listening to connection error emitter on my side, but to no avail. Any ideas on how this could be made to fail gracefully?

    var options = {
        url: globals.amqpUrl,
        heartbeat: 900,
        clientProperties: {
            applicationName: "mobile-app-services",
            capabilities: { consumer_cancel_notify: true }
        }
    };

     // Subscribe to RabbitMQ queue that alerts app of new requests
    RabbitMQ.createConnection(options);
    RabbitMQ.connection.on('ready', Meteor.bindEnvironment(function () {
        RabbitMQ.connection.queue('services.ns', {
                'durable': true,
                'autoDelete': false,
                closeChannelOnUnsubscribe: true
            },
            Meteor.bindEnvironment(function (queue) {
                //do stuff
            }));
    }));
    RabbitMQ.connection.on('error', function(e) {
        logger.debug(e.stack);
    });
jakobloekke commented 9 years ago

I've experienced this as well, so I actually have a mental note to look into it. Just haven't had the time. :) I'll take a look at it later today.

jakobloekke commented 9 years ago

I've added a quickfix for this issue until I find a better way of handling exceptions. Could you let me know if it helps you?

(https://github.com/jakobloekke/jakobloekke-rabbitmq/commit/f12668f924c3540e798ff97d06c2a22bafa801b2)