Skip to content

Instantly share code, notes, and snippets.

@lucj
Created January 14, 2019 10:09
Show Gist options
  • Save lucj/949d8204bdc44d09d1ecd0462a564dd4 to your computer and use it in GitHub Desktop.
Save lucj/949d8204bdc44d09d1ecd0462a564dd4 to your computer and use it in GitHub Desktop.
mq-reconnect.js
...
conn.on("close", function() {
winston.error("-> mq.connection: close event received");
mq.channel = null;
// Try to reconnect every X seconds
const timer = setInterval(function () {
winston.info('-> mq.connection: trying to reconnect...');
mq.connect((err) => {
if (err) {
winston.error(util.format("-> mq.connection: reconnection failed [%s]", err.message));
} else {
winston.info(util.format("-> app: mq.connect succeeded"));
clearInterval(timer);
}
});
}, 3000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment