Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.js process dies if RabbitMQ node dies. #93

Closed
aangelidis opened this issue Mar 8, 2017 · 8 comments
Closed

Node.js process dies if RabbitMQ node dies. #93

aangelidis opened this issue Mar 8, 2017 · 8 comments

Comments

@aangelidis
Copy link

Hi,

I have the following.

const servicebus = require('servicebus');
const retry = require('servicebus-retry');

bus = servicebus.bus({
    url: 'amqp://localhost:6672'
});
bus.use(retry({
    store: new retry.MemoryStore()
}));

// This will set autoDelete to false, but we must manually ack messages.
var options = {
    ack: true
}

bus.subscribe('events.*', options, (msg) => {
        msg.handle.ack(() => {
            console.log('Acked message: ' + JSON.stringify(msg));
        });
});

console.log("events-management started.");

The moment the Rabbit node where servicebus is connected to dies (dokcer kill that 1 node), the Node.js process dies also with no exception caught.

We only see: Process finished with exit code 0

@mateodelnorte
Copy link
Owner

By adding a bus.on('connection.closed', fn), you can latch on to the connection closing:

const servicebus = require('servicebus');
const retry = require('servicebus-retry');

bus = servicebus.bus({
  url: 'amqp://localhost:5672'
});
bus.use(retry({
  store: new retry.MemoryStore()
}));

// This will set autoDelete to false, but we must manually ack messages.
var options = {
  ack: true
}

bus.subscribe('events.*', options, (msg) => {
  msg.handle.ack(() => {
    console.log('Acked message: ' + JSON.stringify(msg));
  });
});

console.log("events-management started.");

process.on('uncaughtException', (err) => {
  console.log(err);
});

bus.on('connection.close', console.log.bind(this, 'connection.close'))

This probably should be emitted as an error on bus, itself. I'll spin up a quick PR, reference you, and you can see if it fits what you'd like.

@aangelidis
Copy link
Author

Thanks. :) I'm wondering if it's worth putting a reconnect option with retries. Especially if using HAProxy load balancing.

@aangelidis
Copy link
Author

Btw, this doesn't fire...
process.on('uncaughtException', (err) => { console.log('Here: ' + err); });

This does...
bus.on('connection.close', console.log.bind(this, 'connection.close'))

@mateodelnorte
Copy link
Owner

I'm debugging the uncaughtException issue now. Looks like it's coming from amqplib. Just raised the following issue there: amqp-node/amqplib#334

For now, the best thing to do is listen for connection.close. I'll update here as soon as I hear back.

In general, I promote crashing your application and restarting when an error occurs (https://www.joyent.com/node-js/production/design/errors). If you'd like to write a module that wraps servicebus and provides retry-connection with incremental backoff, I'd be happy to link to it.

@aangelidis
Copy link
Author

Ok. I'll track it here.

@javadevmtl
Copy link

Btw is there a way to contact you so we can discuss the docs a bit see if I can document some of it for you? :)

@mateodelnorte
Copy link
Owner

Yup. Shoot me a dm on nycnode.com/slack

@mateodelnorte
Copy link
Owner

Circling back here with a better way to communicate about helping out!

https://gitter.im/servicebus-node/Lobby

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants