@autofleet/rabbit 3.2.4-beta.0 → 3.2.5
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 +3 -2
- package/dist/index.js +22 -4
- package/package.json +1 -1
- package/src/index.ts +23 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { AmqpConnectionManager, ChannelWrapper } from 'amqp-connection-manager';
|
|
3
|
+
import { AmqpConnectionManager, ChannelWrapper, CreateChannelOpts } from 'amqp-connection-manager';
|
|
4
4
|
import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
|
|
5
5
|
import { RedisConfig } from './lib/redis';
|
|
6
6
|
import { TRACING_HEADER, USER_TRACING_HEADER } from './lib/consts';
|
|
@@ -37,6 +37,7 @@ export interface AfRabbitOptions {
|
|
|
37
37
|
declare type newChannelOpts = {
|
|
38
38
|
name?: string;
|
|
39
39
|
onClose?: null | ((args: any | null) => void);
|
|
40
|
+
options?: CreateChannelOpts | undefined;
|
|
40
41
|
};
|
|
41
42
|
declare type assertChannelOpts = {
|
|
42
43
|
channelName?: string;
|
|
@@ -75,7 +76,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
75
76
|
ack: (channel: ConfirmChannel, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean, releaseLock?: null) => (userMsg: ConsumeMessage) => Promise<any>;
|
|
76
77
|
nack: (channel: ConfirmChannel, queue: string, options: any, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull, releaseLock: any) => (userMsg: ConsumeMessageOrNull, { skipRetry, }?: NackOptions) => Promise<any>;
|
|
77
78
|
getConnection(): Promise<AmqpConnectionManager>;
|
|
78
|
-
getNewChannel({ name, onClose }?: newChannelOpts): Promise<ChannelWrapper>;
|
|
79
|
+
getNewChannel({ name, onClose, options }?: newChannelOpts): Promise<ChannelWrapper>;
|
|
79
80
|
assertChannel({ force }?: assertChannelOpts): Promise<ChannelWrapper>;
|
|
80
81
|
assertExchange(exchangeName: string, options?: any): Promise<any>;
|
|
81
82
|
getQueueLength(queue: string): Promise<Replies.AssertQueue>;
|
package/dist/index.js
CHANGED
|
@@ -183,6 +183,7 @@ class RabbitMq {
|
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
this.connection.on('connectFailed', (err) => {
|
|
186
|
+
this.consumersTags = [];
|
|
186
187
|
logger_1.default.error('rabbit: connection connectFailed', { err });
|
|
187
188
|
if (!isResolved) {
|
|
188
189
|
isResolved = true;
|
|
@@ -191,6 +192,7 @@ class RabbitMq {
|
|
|
191
192
|
}
|
|
192
193
|
});
|
|
193
194
|
this.connection.on('disconnect', ({ err }) => {
|
|
195
|
+
this.consumersTags = [];
|
|
194
196
|
debug('rabbit: connection closed');
|
|
195
197
|
if (this.options?.disableReconnect) {
|
|
196
198
|
logger_1.default.error(`${this.DISCONNECT_MSG}${err && ` - ${err}`}`);
|
|
@@ -209,10 +211,12 @@ class RabbitMq {
|
|
|
209
211
|
});
|
|
210
212
|
});
|
|
211
213
|
}
|
|
212
|
-
async getNewChannel({ name = utils_1.rand().toString(), onClose = null } = {}) {
|
|
214
|
+
async getNewChannel({ name = utils_1.rand().toString(), onClose = null, options = {} } = {}) {
|
|
213
215
|
return new Promise(async (resolve, reject) => {
|
|
214
216
|
const connection = await this.getConnection();
|
|
215
|
-
const channel = connection.createChannel({
|
|
217
|
+
const channel = connection.createChannel({
|
|
218
|
+
...options,
|
|
219
|
+
});
|
|
216
220
|
let isResolved = false;
|
|
217
221
|
channel.on('error', (err) => {
|
|
218
222
|
logger_1.default.error(`rabbit: channel error ${name} error`, { err });
|
|
@@ -374,7 +378,7 @@ class RabbitMq {
|
|
|
374
378
|
}
|
|
375
379
|
catch (e) {
|
|
376
380
|
logger_1.default.error('rabbit: failed to setRabbitTrace', { userId, e });
|
|
377
|
-
|
|
381
|
+
return this.nack(confirmChannel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg, releaseLock)(msg);
|
|
378
382
|
}
|
|
379
383
|
}
|
|
380
384
|
if (traceId) {
|
|
@@ -468,7 +472,21 @@ class RabbitMq {
|
|
|
468
472
|
}
|
|
469
473
|
async isConnected() {
|
|
470
474
|
const connection = await this.getConnection();
|
|
471
|
-
|
|
475
|
+
const isConnected = connection.isConnected();
|
|
476
|
+
if (!isConnected) {
|
|
477
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
const channel = await this.assertChannel();
|
|
481
|
+
try {
|
|
482
|
+
await channel.waitForConnect();
|
|
483
|
+
}
|
|
484
|
+
catch (e) {
|
|
485
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
logger_1.default.info('rabbit: isConnected - true');
|
|
489
|
+
return true;
|
|
472
490
|
}
|
|
473
491
|
async gracefulShutdown(signal) {
|
|
474
492
|
const tagsNumber = this.consumersTags.length;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { EventEmitter } from 'events';
|
|
|
4
4
|
import { promisify } from 'util';
|
|
5
5
|
import moment from 'moment';
|
|
6
6
|
import RedisLock from 'redis-lock';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
AmqpConnectionManager, ChannelWrapper, connect, CreateChannelOpts,
|
|
9
|
+
} from 'amqp-connection-manager';
|
|
8
10
|
import {
|
|
9
11
|
ConfirmChannel, ConsumeMessage, Options, Replies,
|
|
10
12
|
} from 'amqplib';
|
|
@@ -78,6 +80,7 @@ export interface AfRabbitOptions {
|
|
|
78
80
|
type newChannelOpts = {
|
|
79
81
|
name?: string;
|
|
80
82
|
onClose?: null | ((args: any | null) => void);
|
|
83
|
+
options?: CreateChannelOpts | undefined;
|
|
81
84
|
};
|
|
82
85
|
|
|
83
86
|
type assertChannelOpts = {
|
|
@@ -312,6 +315,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
312
315
|
});
|
|
313
316
|
|
|
314
317
|
this.connection.on('connectFailed', (err) => {
|
|
318
|
+
this.consumersTags = [];
|
|
315
319
|
logger.error('rabbit: connection connectFailed', { err });
|
|
316
320
|
if (!isResolved) {
|
|
317
321
|
isResolved = true;
|
|
@@ -321,6 +325,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
321
325
|
});
|
|
322
326
|
|
|
323
327
|
this.connection.on('disconnect', ({ err }) => {
|
|
328
|
+
this.consumersTags = [];
|
|
324
329
|
debug('rabbit: connection closed');
|
|
325
330
|
if (this.options?.disableReconnect) {
|
|
326
331
|
logger.error(`${this.DISCONNECT_MSG}${err && ` - ${err}`}`);
|
|
@@ -339,10 +344,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
339
344
|
});
|
|
340
345
|
}
|
|
341
346
|
|
|
342
|
-
async getNewChannel({ name = rand().toString(), onClose = null }: newChannelOpts = {}) {
|
|
347
|
+
async getNewChannel({ name = rand().toString(), onClose = null, options = {} }: newChannelOpts = {}) {
|
|
343
348
|
return new Promise<ChannelWrapper>(async (resolve, reject) => {
|
|
344
349
|
const connection: AmqpConnectionManager = await this.getConnection();
|
|
345
350
|
const channel = connection.createChannel({
|
|
351
|
+
...options,
|
|
346
352
|
});
|
|
347
353
|
|
|
348
354
|
let isResolved = false;
|
|
@@ -526,7 +532,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
526
532
|
]);
|
|
527
533
|
} catch (e) {
|
|
528
534
|
logger.error('rabbit: failed to setRabbitTrace', { userId, e });
|
|
529
|
-
|
|
535
|
+
return this.nack(confirmChannel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg, releaseLock)(msg);
|
|
530
536
|
}
|
|
531
537
|
}
|
|
532
538
|
|
|
@@ -647,7 +653,20 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
647
653
|
|
|
648
654
|
async isConnected() : Promise<boolean> {
|
|
649
655
|
const connection = await this.getConnection();
|
|
650
|
-
|
|
656
|
+
const isConnected = connection.isConnected();
|
|
657
|
+
if (!isConnected) {
|
|
658
|
+
logger.error('rabbit: isConnected - false');
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
const channel = await this.assertChannel();
|
|
662
|
+
try {
|
|
663
|
+
await channel.waitForConnect();
|
|
664
|
+
} catch (e) {
|
|
665
|
+
logger.error('rabbit: isConnected - false');
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
logger.info('rabbit: isConnected - true');
|
|
669
|
+
return true;
|
|
651
670
|
}
|
|
652
671
|
|
|
653
672
|
async gracefulShutdown(signal: string) : Promise<void> {
|