Skip to content

Instantly share code, notes, and snippets.

@tcastelly
Forked from lucj/mq-reconnect.js
Last active January 14, 2019 11:37
Show Gist options
  • Save tcastelly/2b3b2b82169c212d2ce3ff7e1f7e0236 to your computer and use it in GitHub Desktop.
Save tcastelly/2b3b2b82169c212d2ce3ff7e1f7e0236 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
let 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