@autofleet/rabbit 3.2.13-beta.1 → 3.2.13-beta.11
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 +21 -18
- package/package.json +2 -2
- package/src/index.ts +22 -19
package/dist/index.js
CHANGED
|
@@ -229,24 +229,26 @@ class RabbitMq {
|
|
|
229
229
|
...options,
|
|
230
230
|
});
|
|
231
231
|
let isResolved = false;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
if (channel) {
|
|
233
|
+
channel.on('error', (err) => {
|
|
234
|
+
logger_1.default.error(`rabbit: channel error ${name} error`, { err });
|
|
235
|
+
if (!isResolved) {
|
|
236
|
+
isResolved = true;
|
|
237
|
+
reject(err);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
channel.on('close', (...args) => {
|
|
241
|
+
logger_1.default.error(`rabbit: channel ${name} closed`, { args });
|
|
242
|
+
if (onClose) {
|
|
243
|
+
onClose(args);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
channel.once('connect', () => {
|
|
247
|
+
debug(`rabbit: channel ${name} CONNECTED`);
|
|
235
248
|
isResolved = true;
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
channel.on('close', (...args) => {
|
|
240
|
-
logger_1.default.error(`rabbit: channel ${name} closed`, { args });
|
|
241
|
-
if (onClose) {
|
|
242
|
-
onClose(args);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
channel.once('connect', () => {
|
|
246
|
-
debug(`rabbit: channel ${name} CONNECTED`);
|
|
247
|
-
isResolved = true;
|
|
248
|
-
resolve(channel);
|
|
249
|
-
});
|
|
249
|
+
resolve(channel);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
250
252
|
});
|
|
251
253
|
}
|
|
252
254
|
async assertChannel({ force = false } = {}) {
|
|
@@ -332,6 +334,7 @@ class RabbitMq {
|
|
|
332
334
|
saveConsumer(queue, callback, options) {
|
|
333
335
|
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
334
336
|
if (!isConsumerExist) {
|
|
337
|
+
logger_1.default.info(`rabbit: consumer: ${queue} saved in consumer array`);
|
|
335
338
|
this.consumers.push({
|
|
336
339
|
queue,
|
|
337
340
|
callback,
|
|
@@ -341,7 +344,6 @@ class RabbitMq {
|
|
|
341
344
|
}
|
|
342
345
|
async consume(queue, callback, options) {
|
|
343
346
|
await this.consumeFromRabbit(queue, callback, options);
|
|
344
|
-
return this.saveConsumer(queue, callback, options);
|
|
345
347
|
}
|
|
346
348
|
async lockRedisIfNeeded(msg, options) {
|
|
347
349
|
const { properties: { headers } } = msg;
|
|
@@ -360,6 +362,7 @@ class RabbitMq {
|
|
|
360
362
|
async consumeFromRabbit(queue, callback, options) {
|
|
361
363
|
const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
|
|
362
364
|
RabbitMq.validateName('queue', queue);
|
|
365
|
+
this.saveConsumer(queue, callback, options);
|
|
363
366
|
const uniqueId = uuid_1.v4();
|
|
364
367
|
const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace, } = optionsWithDefaults;
|
|
365
368
|
if (useConsumeWithLock) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.2.13-beta.
|
|
3
|
+
"version": "3.2.13-beta.11",
|
|
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.
|
|
19
|
+
"@autofleet/zehut": "^3.0.6",
|
|
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
|
@@ -362,24 +362,26 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
362
362
|
});
|
|
363
363
|
|
|
364
364
|
let isResolved = false;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
365
|
+
if (channel) {
|
|
366
|
+
channel.on('error', (err) => {
|
|
367
|
+
logger.error(`rabbit: channel error ${name} error`, { err });
|
|
368
|
+
if (!isResolved) {
|
|
369
|
+
isResolved = true;
|
|
370
|
+
reject(err);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
channel.on('close', (...args) => {
|
|
374
|
+
logger.error(`rabbit: channel ${name} closed`, { args });
|
|
375
|
+
if (onClose) {
|
|
376
|
+
onClose(args);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
channel.once('connect', () => {
|
|
380
|
+
debug(`rabbit: channel ${name} CONNECTED`);
|
|
368
381
|
isResolved = true;
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
channel.on('close', (...args) => {
|
|
373
|
-
logger.error(`rabbit: channel ${name} closed`, { args });
|
|
374
|
-
if (onClose) {
|
|
375
|
-
onClose(args);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
channel.once('connect', () => {
|
|
379
|
-
debug(`rabbit: channel ${name} CONNECTED`);
|
|
380
|
-
isResolved = true;
|
|
381
|
-
resolve(channel);
|
|
382
|
-
});
|
|
382
|
+
resolve(channel);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
383
385
|
});
|
|
384
386
|
}
|
|
385
387
|
|
|
@@ -470,8 +472,9 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
470
472
|
}
|
|
471
473
|
|
|
472
474
|
private saveConsumer(queue: string, callback: CallbackFunction, options: ConsumeOptions | undefined) {
|
|
473
|
-
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
475
|
+
const isConsumerExist :boolean = this.consumers.some((consumer) => consumer.queue === queue);
|
|
474
476
|
if (!isConsumerExist) {
|
|
477
|
+
logger.info(`rabbit: consumer: ${queue} saved in consumer array`);
|
|
475
478
|
this.consumers.push({
|
|
476
479
|
queue,
|
|
477
480
|
callback,
|
|
@@ -482,7 +485,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
482
485
|
|
|
483
486
|
async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
484
487
|
await this.consumeFromRabbit(queue, callback, options);
|
|
485
|
-
return this.saveConsumer(queue, callback, options);
|
|
486
488
|
}
|
|
487
489
|
|
|
488
490
|
private async lockRedisIfNeeded(msg: any, options: any) {
|
|
@@ -508,6 +510,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
508
510
|
private async consumeFromRabbit(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
509
511
|
const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
|
|
510
512
|
RabbitMq.validateName('queue', queue);
|
|
513
|
+
this.saveConsumer(queue, callback, options);
|
|
511
514
|
const uniqueId = v4();
|
|
512
515
|
const {
|
|
513
516
|
limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace,
|