Skip to content

Commit

Permalink
add tracking to amqp disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Oct 4, 2021
1 parent 3f861e0 commit 5ec3393
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/adapters/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,30 @@ class AmqpAdapter extends BaseAdapter {
this.stopping = true;
try {
if (this.connection) {
this.logger.info("Closing AMQP connection...");
await this.connection.close();
this.connection = null;
this.channel = null;
await new Promise((resolve, reject) => {
const checkPendingMessages = () => {
if (this.getNumberOfTrackedChannels() === 0) {
// Stop the connection
this.logger.info("Closing AMQP connection...");
return this.connection
.close()
.then(() => {
this.connection = null;
this.channel = null;
resolve();
})
.catch(reject);
} else {
this.logger.warn(
`Processing ${this.getNumberOfTrackedChannels()} active connections(s)...`
);

setTimeout(checkPendingMessages, 1000);
}
};

setImmediate(checkPendingMessages);
});
}
} catch (err) {
this.logger.error("Error while closing AMQP connection.", err);
Expand Down

0 comments on commit 5ec3393

Please sign in to comment.