rabbitmq pika publish connection closed code example
Example: node close rabbitmq connection
async sendMsg(msg) {
const channel = await this.initChannel();
const sendResult = channel.sendToQueue(this.queue, Buffer.from(msg), {
persistent: true,
});
if (!sendResult) {
await new Promise((resolve) => channel.once('drain', () => resolve));
}
}
async close() {
if (this.channel) await this.channel.close();
await this.conn.close();
}