Skip to content

Commit

Permalink
fix: channel and connection closure added
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosCarmona committed Nov 9, 2020
1 parent 60e0764 commit 3f293fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand All @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 3f293fb

Please sign in to comment.