@autofleet/rabbit 3.2.13-beta.1 → 3.2.13-beta.10
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 +24 -18
- package/package.json +2 -2
- package/src/index.ts +24 -19
package/dist/index.js
CHANGED
|
@@ -229,24 +229,29 @@ 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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
debug(`rabbit: channel ${name} not connected and therefore no listener was registered`);
|
|
254
|
+
}
|
|
250
255
|
});
|
|
251
256
|
}
|
|
252
257
|
async assertChannel({ force = false } = {}) {
|
|
@@ -332,6 +337,7 @@ class RabbitMq {
|
|
|
332
337
|
saveConsumer(queue, callback, options) {
|
|
333
338
|
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
334
339
|
if (!isConsumerExist) {
|
|
340
|
+
logger_1.default.info(`rabbit: consumer: ${queue} saved in consumer array`);
|
|
335
341
|
this.consumers.push({
|
|
336
342
|
queue,
|
|
337
343
|
callback,
|
|
@@ -341,7 +347,6 @@ class RabbitMq {
|
|
|
341
347
|
}
|
|
342
348
|
async consume(queue, callback, options) {
|
|
343
349
|
await this.consumeFromRabbit(queue, callback, options);
|
|
344
|
-
return this.saveConsumer(queue, callback, options);
|
|
345
350
|
}
|
|
346
351
|
async lockRedisIfNeeded(msg, options) {
|
|
347
352
|
const { properties: { headers } } = msg;
|
|
@@ -360,6 +365,7 @@ class RabbitMq {
|
|
|
360
365
|
async consumeFromRabbit(queue, callback, options) {
|
|
361
366
|
const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
|
|
362
367
|
RabbitMq.validateName('queue', queue);
|
|
368
|
+
this.saveConsumer(queue, callback, options);
|
|
363
369
|
const uniqueId = uuid_1.v4();
|
|
364
370
|
const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace, } = optionsWithDefaults;
|
|
365
371
|
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.10",
|
|
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,28 @@ 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
|
-
|
|
373
|
-
|
|
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
|
+
} else {
|
|
385
|
+
debug(`rabbit: channel ${name} not connected and therefore no listener was registered`);
|
|
386
|
+
}
|
|
383
387
|
});
|
|
384
388
|
}
|
|
385
389
|
|
|
@@ -470,8 +474,9 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
470
474
|
}
|
|
471
475
|
|
|
472
476
|
private saveConsumer(queue: string, callback: CallbackFunction, options: ConsumeOptions | undefined) {
|
|
473
|
-
const isConsumerExist = this.consumers.some((consumer) => consumer.queue === queue);
|
|
477
|
+
const isConsumerExist :boolean = this.consumers.some((consumer) => consumer.queue === queue);
|
|
474
478
|
if (!isConsumerExist) {
|
|
479
|
+
logger.info(`rabbit: consumer: ${queue} saved in consumer array`);
|
|
475
480
|
this.consumers.push({
|
|
476
481
|
queue,
|
|
477
482
|
callback,
|
|
@@ -482,7 +487,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
482
487
|
|
|
483
488
|
async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
484
489
|
await this.consumeFromRabbit(queue, callback, options);
|
|
485
|
-
return this.saveConsumer(queue, callback, options);
|
|
486
490
|
}
|
|
487
491
|
|
|
488
492
|
private async lockRedisIfNeeded(msg: any, options: any) {
|
|
@@ -508,6 +512,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
508
512
|
private async consumeFromRabbit(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
509
513
|
const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
|
|
510
514
|
RabbitMq.validateName('queue', queue);
|
|
515
|
+
this.saveConsumer(queue, callback, options);
|
|
511
516
|
const uniqueId = v4();
|
|
512
517
|
const {
|
|
513
518
|
limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace,
|