Skip to content

Commit

Permalink
Merge pull request #1 from taina0407/develop
Browse files Browse the repository at this point in the history
v1.1.3
  • Loading branch information
taina0407 authored May 1, 2021
2 parents 7764b27 + c61aec0 commit ce3582f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.1.3
- [Fix]
- Fix bug graceful shutdown not cancel consumer

## v1.1.2
- [Fix]
- Fix bug using merge-deep instead of defaults-deep
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moleculer-rabbitmq",
"version": "1.1.2",
"version": "1.1.3",
"description": "Moleculer RabbitMQ queue plugin",
"main": "index.js",
"scripts": {
Expand Down
14 changes: 8 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const Crypto = require("crypto");
const Amqplib = require("amqplib");
const DefaultDeep = require("defaults-deep");
const Deep = require("deep-get-set");
Expand Down Expand Up @@ -59,9 +58,10 @@ const ACTION_OPTIONS_VALIDATOR = {
const gracefulShutdown = async function () {
isShuttingDown = true;

Object.keys(this.$amqpQueues).forEach((queueName) => {
const { channel, options } = this.$amqpQueues[queueName] || {};
channel && channel.cancel(Deep(options, "amqp.consume.consumerTag"));
Object.keys(this.$amqpQueues).forEach(async (queueName) => {
const { channel, consumerTag } = this.$amqpQueues[queueName] || {};

channel && consumerTag && await channel.cancel(consumerTag);
});
};

Expand All @@ -80,7 +80,6 @@ const initAMQPQueues = function (schema) {
const queueName = `amqp.${schema.version ? `v${schema.version}.` : ""}${schema.name}.${originActionName}`;

const queueOption = DefaultDeep({}, schema.actions[originActionName].queue, DEFAULT_QUEUE_OPTIONS);
Deep(queueOption, "amqp.consume.consumerTag", Crypto.randomBytes(16).toString("hex"));

this.$amqpQueues[queueName] = {
options: queueOption,
Expand Down Expand Up @@ -267,7 +266,10 @@ module.exports = (options) => ({
} = queue;

const amqpChannel = await this.assertAMQPQueue(queueName);
amqpChannel.consume(queueName, consumeHandler.bind(this, amqpChannel), consumeOptions);
const {
consumerTag,
} = await amqpChannel.consume(queueName, consumeHandler.bind(this, amqpChannel), consumeOptions);
this.$amqpQueues[queueName].consumerTag = consumerTag;
});
},
},
Expand Down

0 comments on commit ce3582f

Please sign in to comment.