@autofleet/rabbit 2.1.12-beta2 → 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
@@ -12,6 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ /* eslint-disable @typescript-eslint/ban-ts-comment,@typescript-eslint/ban-types,@typescript-eslint/no-unused-vars,consistent-return,no-async-promise-executor,no-param-reassign,no-empty */
16
+ // eslint-disable-next-line max-classes-per-file
15
17
  const moment_1 = __importDefault(require("moment"));
16
18
  const amqp_connection_manager_1 = require("amqp-connection-manager");
17
19
  const events_1 = require("events");
@@ -74,6 +76,7 @@ class RabbitMq {
74
76
  this.connection = null;
75
77
  this.creatingConnection = false;
76
78
  this.exchanges = {};
79
+ this.queues = {};
77
80
  this.options = options;
78
81
  this.redisClient = redisConfig && redis_1.default(redisConfig);
79
82
  }
@@ -160,11 +163,9 @@ class RabbitMq {
160
163
  if (this.exchanges[exchangeName]) {
161
164
  return this.exchanges[exchangeName];
162
165
  }
163
- return channel.addSetup((c) => __awaiter(this, void 0, void 0, function* () {
164
- const exchange = yield assertExchangeFanout(c, exchangeName);
165
- this.exchanges[exchangeName] = exchange;
166
- return exchange;
167
- }));
166
+ const exchange = yield assertExchangeFanout(channel, exchangeName);
167
+ this.exchanges[exchangeName] = exchange;
168
+ return exchange;
168
169
  });
169
170
  }
170
171
  getQueueLength(queue) {
@@ -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-beta2",
3
+ "version": "2.1.13",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/ban-ts-comment,@typescript-eslint/ban-types,@typescript-eslint/no-unused-vars,consistent-return,no-async-promise-executor,no-param-reassign,no-empty */
2
2
  // eslint-disable-next-line max-classes-per-file
3
- import * as bluebird from 'bluebird';
4
3
  import moment from 'moment';
5
4
  import { ConfirmChannel, Options } from 'amqplib';
6
5
  import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-manager';
@@ -26,6 +25,9 @@ export interface IAfRabbitMq {
26
25
  interface ExchangesCache {
27
26
  [key: string]: any
28
27
  }
28
+ interface QueuesCache {
29
+ [key: string]: any
30
+ }
29
31
 
30
32
  type CustomMessageHeaders = {
31
33
  redisTimestampValidationKey?: string;
@@ -93,6 +95,8 @@ class RabbitMq implements IAfRabbitMq {
93
95
 
94
96
  exchanges: ExchangesCache;
95
97
 
98
+ queues: QueuesCache;
99
+
96
100
  options: AfRabbitOptions | undefined;
97
101
 
98
102
  redisClient: any;
@@ -103,6 +107,7 @@ class RabbitMq implements IAfRabbitMq {
103
107
  this.connection = null;
104
108
  this.creatingConnection = false;
105
109
  this.exchanges = {};
110
+ this.queues = {};
106
111
  this.options = options;
107
112
  this.redisClient = redisConfig && getRedisInstance(redisConfig);
108
113
  }
@@ -214,11 +219,9 @@ class RabbitMq implements IAfRabbitMq {
214
219
  if (this.exchanges[exchangeName]) {
215
220
  return this.exchanges[exchangeName];
216
221
  }
217
- return channel.addSetup(async (c: ConfirmChannel) => {
218
- const exchange = await assertExchangeFanout(c, exchangeName);
219
- this.exchanges[exchangeName] = exchange;
220
- return exchange;
221
- });
222
+ const exchange = await assertExchangeFanout(channel, exchangeName);
223
+ this.exchanges[exchangeName] = exchange;
224
+ return exchange;
222
225
  }
223
226
 
224
227
  async getQueueLength(queue: string) {
@@ -237,6 +240,9 @@ class RabbitMq implements IAfRabbitMq {
237
240
  async assertQueue(queue: string, options?: Options.AssertQueue) {
238
241
  RabbitMq.validateName('queue', queue);
239
242
  const channel: ChannelWrapper = await this.assertChannel();
243
+ if (this.queues[queue]) {
244
+ return this.queues[queue];
245
+ }
240
246
  return channel.assertQueue(queue, options);
241
247
  }
242
248
 
package/.env DELETED
File without changes
package/dump.rdb DELETED
Binary file