From 3f293fb4030834bb96f50d7f41efcfb8ccf94947 Mon Sep 17 00:00:00 2001 From: CarlosCarmona Date: Mon, 9 Nov 2020 12:23:23 +0100 Subject: [PATCH] fix: channel and connection closure added --- index.js | 10 +++++++--- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 80ee225..80f0cfb 100755 --- a/index.js +++ b/index.js @@ -45,14 +45,14 @@ class amqpExecutor extends Execution { try { const connection = await amqp.connect(connectOptions); const channel = await connection.createChannel(); - return channel; + return [connection, channel]; } catch (err) { throw new Error(err.message); } } async sendMessageToQueue() { - const channel = await this.connect(); + const [connection, channel] = await this.connect(); await channel.assertQueue(this.options.queue); const sendResponse = channel.sendToQueue( @@ -64,12 +64,14 @@ class amqpExecutor extends Execution { if (!sendResponse) { throw new Error(`Message not sended: ${this.options.message} to ${this.options.queue} queue.`); } + await channel.close(); + connection.close(); } async sendMessageToExange() { if (!this.options.exangeType) throw new Error(`For publish in exange you must set the exangeType.`); - const channel = await this.connect(); + const [connection, channel] = await this.connect(); if (this.options.queue) { await channel.assertQueue(this.options.queue); } @@ -85,6 +87,8 @@ class amqpExecutor extends Execution { if (!sendResponse) { throw new Error(`Message not sended: ${this.options.message} to ${this.options.exange} exange.`); } + await channel.close(); + connection.close(); } } diff --git a/package-lock.json b/package-lock.json index c912dfb..34cede2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@runnerty/executor-amqp", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 100a821..05885d2 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@runnerty/executor-amqp", - "version": "2.0.0", + "version": "2.0.1", "description": "Runnerty module: AMQP Publisher", "author": "Runnerty Tech", "license": "MIT",