@autofleet/rabbit 2.1.12 → 2.1.13

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.d.ts CHANGED
@@ -18,6 +18,9 @@ export interface IAfRabbitMq {
18
18
  interface ExchangesCache {
19
19
  [key: string]: any;
20
20
  }
21
+ interface QueuesCache {
22
+ [key: string]: any;
23
+ }
21
24
  declare type CustomMessageHeaders = {
22
25
  redisTimestampValidationKey?: string;
23
26
  };
@@ -40,6 +43,7 @@ declare class RabbitMq implements IAfRabbitMq {
40
43
  em: EventEmitter;
41
44
  creatingConnection: boolean;
42
45
  exchanges: ExchangesCache;
46
+ queues: QueuesCache;
43
47
  options: AfRabbitOptions | undefined;
44
48
  redisClient: any;
45
49
  constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig);
@@ -52,7 +56,7 @@ declare class RabbitMq implements IAfRabbitMq {
52
56
  assertExchange(exchangeName: string, options?: any): Promise<any>;
53
57
  getQueueLength(queue: string): Promise<import("amqplib").Replies.AssertQueue>;
54
58
  bindQueue(queue: string, exchange: string): Promise<void>;
55
- assertQueue(queue: string, options?: Options.AssertQueue): Promise<import("amqplib").Replies.AssertQueue>;
59
+ assertQueue(queue: string, options?: Options.AssertQueue): Promise<any>;
56
60
  consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
57
61
  consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
58
62
  publish(exchange: string, content: any, customHeaders?: any): Promise<void>;
package/dist/index.js CHANGED
@@ -76,6 +76,7 @@ class RabbitMq {
76
76
  this.connection = null;
77
77
  this.creatingConnection = false;
78
78
  this.exchanges = {};
79
+ this.queues = {};
79
80
  this.options = options;
80
81
  this.redisClient = redisConfig && redis_1.default(redisConfig);
81
82
  }
@@ -186,6 +187,9 @@ class RabbitMq {
186
187
  return __awaiter(this, void 0, void 0, function* () {
187
188
  RabbitMq.validateName('queue', queue);
188
189
  const channel = yield this.assertChannel();
190
+ if (this.queues[queue]) {
191
+ return this.queues[queue];
192
+ }
189
193
  return channel.assertQueue(queue, options);
190
194
  });
191
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -25,6 +25,9 @@ export interface IAfRabbitMq {
25
25
  interface ExchangesCache {
26
26
  [key: string]: any
27
27
  }
28
+ interface QueuesCache {
29
+ [key: string]: any
30
+ }
28
31
 
29
32
  type CustomMessageHeaders = {
30
33
  redisTimestampValidationKey?: string;
@@ -92,6 +95,8 @@ class RabbitMq implements IAfRabbitMq {
92
95
 
93
96
  exchanges: ExchangesCache;
94
97
 
98
+ queues: QueuesCache;
99
+
95
100
  options: AfRabbitOptions | undefined;
96
101
 
97
102
  redisClient: any;
@@ -102,6 +107,7 @@ class RabbitMq implements IAfRabbitMq {
102
107
  this.connection = null;
103
108
  this.creatingConnection = false;
104
109
  this.exchanges = {};
110
+ this.queues = {};
105
111
  this.options = options;
106
112
  this.redisClient = redisConfig && getRedisInstance(redisConfig);
107
113
  }
@@ -234,6 +240,9 @@ class RabbitMq implements IAfRabbitMq {
234
240
  async assertQueue(queue: string, options?: Options.AssertQueue) {
235
241
  RabbitMq.validateName('queue', queue);
236
242
  const channel: ChannelWrapper = await this.assertChannel();
243
+ if (this.queues[queue]) {
244
+ return this.queues[queue];
245
+ }
237
246
  return channel.assertQueue(queue, options);
238
247
  }
239
248