@autofleet/rabbit 3.2.6 → 3.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ class RabbitMq {
88
88
  this.creatingConnection = false;
89
89
  this.exchanges = {};
90
90
  this.queues = {};
91
+ this.consumers = [];
91
92
  this.options = options;
92
93
  this.redisClient = redisConfig && redis_1.default(redisConfig);
93
94
  if (this.redisClient) {
@@ -329,7 +330,8 @@ class RabbitMq {
329
330
  });
330
331
  }
331
332
  async consume(queue, callback, options) {
332
- return this.consumeFromRabbit(queue, callback, options);
333
+ await this.consumeFromRabbit(queue, callback, options);
334
+ return this.saveConsumer(queue, callback, options);
333
335
  }
334
336
  async lockRedisIfNeeded(msg, options) {
335
337
  const { properties: { headers } } = msg;
@@ -356,7 +358,7 @@ class RabbitMq {
356
358
  }
357
359
  logger_1.default.info(`rabbit: Consuming with lock from queue ${queue} with lockTimeout: ${lockTimeout}ms`);
358
360
  }
359
- const channel = await this.getNewChannel({ name: `consume-queue-${queue}` });
361
+ const channel = await this.assertChannel();
360
362
  return channel.addSetup(async (confirmChannel) => {
361
363
  await confirmChannel.assertQueue(queue, options ? { messageTtl: options.messageTtl } : undefined);
362
364
  await confirmChannel.prefetch(limit, true);
@@ -485,7 +487,10 @@ class RabbitMq {
485
487
  }
486
488
  const channel = await this.assertChannel();
487
489
  try {
488
- await channel.waitForConnect();
490
+ await Promise.all([
491
+ channel.waitForConnect(),
492
+ ...this.consumers.map((c) => channel.checkQueue(c.queue)),
493
+ ]);
489
494
  }
490
495
  catch (e) {
491
496
  logger_1.default.error('rabbit: isConnected - false');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.2.6",
3
+ "version": "3.2.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@autofleet/logger": "^1.2.8",
19
- "@autofleet/zehut": "^3.0.2",
19
+ "@autofleet/zehut": "^3.0.3",
20
20
  "@types/amqplib": "0.8.2",
21
21
  "@types/uuid": "^8.3.3",
22
22
  "amqp-connection-manager": "4.1.9",
package/src/index.ts CHANGED
@@ -171,6 +171,7 @@ class RabbitMq implements IAfRabbitMq {
171
171
  this.creatingConnection = false;
172
172
  this.exchanges = {};
173
173
  this.queues = {};
174
+ this.consumers = [];
174
175
  this.options = options;
175
176
  this.redisClient = redisConfig && getRedisInstance(redisConfig);
176
177
  if (this.redisClient) {
@@ -383,8 +384,7 @@ class RabbitMq implements IAfRabbitMq {
383
384
  }
384
385
 
385
386
  try {
386
- const channel = await this.getNewChannel({
387
- });
387
+ const channel = await this.getNewChannel({});
388
388
  channel.on('error', (err) => {
389
389
  logger.error('rabbit: channel error', { err });
390
390
  });
@@ -472,7 +472,8 @@ class RabbitMq implements IAfRabbitMq {
472
472
  }
473
473
 
474
474
  async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
475
- return this.consumeFromRabbit(queue, callback, options);
475
+ await this.consumeFromRabbit(queue, callback, options);
476
+ return this.saveConsumer(queue, callback, options);
476
477
  }
477
478
 
478
479
  private async lockRedisIfNeeded(msg: any, options: any) {
@@ -508,7 +509,7 @@ class RabbitMq implements IAfRabbitMq {
508
509
  }
509
510
  logger.info(`rabbit: Consuming with lock from queue ${queue} with lockTimeout: ${lockTimeout}ms`);
510
511
  }
511
- const channel: ChannelWrapper = await this.getNewChannel({ name: `consume-queue-${queue}` });
512
+ const channel = await this.assertChannel();
512
513
  return channel.addSetup(async (confirmChannel: ConfirmChannel) => {
513
514
  await confirmChannel.assertQueue(queue, options ? { messageTtl: options.messageTtl } : undefined);
514
515
  await confirmChannel.prefetch(limit, true);
@@ -664,9 +665,12 @@ class RabbitMq implements IAfRabbitMq {
664
665
  logger.error('rabbit: isConnected - false');
665
666
  return false;
666
667
  }
667
- const channel = await this.assertChannel();
668
+ const channel: any = await this.assertChannel();
668
669
  try {
669
- await channel.waitForConnect();
670
+ await Promise.all([
671
+ channel.waitForConnect(),
672
+ ...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
673
+ ]);
670
674
  } catch (e) {
671
675
  logger.error('rabbit: isConnected - false');
672
676
  return false;