@autofleet/rabbit 3.2.13-beta → 3.2.13-beta.1
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 +12 -8
- package/package.json +1 -1
- package/src/index.ts +12 -9
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ class RabbitMq {
|
|
|
25
25
|
constructor(options, redisConfig) {
|
|
26
26
|
this.DISCONNECT_MSG = 'rabbit: connection disconnect';
|
|
27
27
|
this.RECONNECT_MSG = 'rabbit: connection disconnect - reconnecting';
|
|
28
|
+
this.consumers = [];
|
|
28
29
|
this.shouldConsumeMessageByTimestamp = async (msg) => {
|
|
29
30
|
if (msg) {
|
|
30
31
|
const { properties: { headers } } = msg;
|
|
@@ -87,7 +88,7 @@ class RabbitMq {
|
|
|
87
88
|
this.creatingConnection = false;
|
|
88
89
|
this.exchanges = {};
|
|
89
90
|
this.queues = {};
|
|
90
|
-
this.consumers =
|
|
91
|
+
this.consumers = [];
|
|
91
92
|
this.options = options;
|
|
92
93
|
this.redisClient = redisConfig && redis_1.default(redisConfig);
|
|
93
94
|
if (this.redisClient) {
|
|
@@ -224,7 +225,7 @@ class RabbitMq {
|
|
|
224
225
|
logger_1.default.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
225
226
|
reject(e);
|
|
226
227
|
}
|
|
227
|
-
const channel = connection
|
|
228
|
+
const channel = connection?.createChannel({
|
|
228
229
|
...options,
|
|
229
230
|
});
|
|
230
231
|
let isResolved = false;
|
|
@@ -329,11 +330,14 @@ class RabbitMq {
|
|
|
329
330
|
return queue;
|
|
330
331
|
}
|
|
331
332
|
saveConsumer(queue, callback, options) {
|
|
332
|
-
this.consumers.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
333
|
+
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
334
|
+
if (!isConsumerExist) {
|
|
335
|
+
this.consumers.push({
|
|
336
|
+
queue,
|
|
337
|
+
callback,
|
|
338
|
+
options,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
337
341
|
}
|
|
338
342
|
async consume(queue, callback, options) {
|
|
339
343
|
await this.consumeFromRabbit(queue, callback, options);
|
|
@@ -496,7 +500,7 @@ class RabbitMq {
|
|
|
496
500
|
try {
|
|
497
501
|
await Promise.all([
|
|
498
502
|
channel.waitForConnect(),
|
|
499
|
-
...
|
|
503
|
+
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
500
504
|
]);
|
|
501
505
|
}
|
|
502
506
|
catch (e) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -162,7 +162,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
162
162
|
/** Array of consumers tags used for canceling consumption */
|
|
163
163
|
consumersTags: Array<[ConfirmChannel, string]>;
|
|
164
164
|
|
|
165
|
-
private consumers:
|
|
165
|
+
private consumers: Array<AfConsumer> = [];
|
|
166
166
|
|
|
167
167
|
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig) {
|
|
168
168
|
this.em = new EventEmitter();
|
|
@@ -171,7 +171,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
171
171
|
this.creatingConnection = false;
|
|
172
172
|
this.exchanges = {};
|
|
173
173
|
this.queues = {};
|
|
174
|
-
this.consumers =
|
|
174
|
+
this.consumers = [];
|
|
175
175
|
this.options = options;
|
|
176
176
|
this.redisClient = redisConfig && getRedisInstance(redisConfig);
|
|
177
177
|
if (this.redisClient) {
|
|
@@ -357,7 +357,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
357
357
|
logger.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
358
358
|
reject(e);
|
|
359
359
|
}
|
|
360
|
-
const channel = connection
|
|
360
|
+
const channel = connection?.createChannel({
|
|
361
361
|
...options,
|
|
362
362
|
});
|
|
363
363
|
|
|
@@ -470,11 +470,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
470
470
|
}
|
|
471
471
|
|
|
472
472
|
private saveConsumer(queue: string, callback: CallbackFunction, options: ConsumeOptions | undefined) {
|
|
473
|
-
this.consumers.
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
473
|
+
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
474
|
+
if (!isConsumerExist) {
|
|
475
|
+
this.consumers.push({
|
|
476
|
+
queue,
|
|
477
|
+
callback,
|
|
478
|
+
options,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
478
481
|
}
|
|
479
482
|
|
|
480
483
|
async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
@@ -676,7 +679,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
676
679
|
try {
|
|
677
680
|
await Promise.all([
|
|
678
681
|
channel.waitForConnect(),
|
|
679
|
-
...
|
|
682
|
+
...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
680
683
|
]);
|
|
681
684
|
} catch (e) {
|
|
682
685
|
logger.error('rabbit: isConnected - false');
|