@autofleet/rabbit 3.2.22-beta.1 → 3.2.22-beta.3
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 +2 -2
- package/dist/index.js +25 -31
- package/package.json +1 -1
- package/src/index.ts +27 -32
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ type newChannelOpts = {
|
|
|
37
37
|
name?: string;
|
|
38
38
|
onClose?: null | ((args: any | null) => void);
|
|
39
39
|
options?: CreateChannelOpts | undefined;
|
|
40
|
-
connectionPurpose
|
|
40
|
+
connectionPurpose?: ConnectionPurpose;
|
|
41
41
|
};
|
|
42
42
|
type assertChannelOpts = {
|
|
43
43
|
channelName?: string;
|
|
@@ -97,7 +97,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
97
97
|
consumeFromExchange(queue: string, exchange: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any>;
|
|
98
98
|
publish(exchange: string, content: any, customHeaders?: any): Promise<boolean>;
|
|
99
99
|
sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<boolean | undefined>;
|
|
100
|
-
isConnected(
|
|
100
|
+
isConnected(): Promise<boolean>;
|
|
101
101
|
gracefulShutdown(signal: string): Promise<void>;
|
|
102
102
|
}
|
|
103
103
|
export default RabbitMq;
|
package/dist/index.js
CHANGED
|
@@ -182,10 +182,6 @@ class RabbitMq {
|
|
|
182
182
|
const newConnection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
|
|
183
183
|
findServers,
|
|
184
184
|
});
|
|
185
|
-
if (!newConnection) {
|
|
186
|
-
logger_1.default.error('rabbit: couldnt create a connection');
|
|
187
|
-
return resolve(connection);
|
|
188
|
-
}
|
|
189
185
|
this.connectionsMap[connectionPurpose].connection = newConnection;
|
|
190
186
|
newConnection.on('error', (err) => {
|
|
191
187
|
logger_1.default.error('rabbit: connection error', { err });
|
|
@@ -463,7 +459,7 @@ class RabbitMq {
|
|
|
463
459
|
RabbitMq.validateName('queue', queue);
|
|
464
460
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
465
461
|
await this.saveConsumer(queue, callback, options);
|
|
466
|
-
const channel = await this.getNewChannel({ name: `consume - exchange - ${exchange} -queue - ${queue}
|
|
462
|
+
const channel = await this.getNewChannel({ name: `consume - exchange - ${exchange} -queue - ${queue}` });
|
|
467
463
|
return channel.addSetup(async (c) => {
|
|
468
464
|
const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
|
|
469
465
|
await c.assertQueue(queue);
|
|
@@ -505,35 +501,33 @@ class RabbitMq {
|
|
|
505
501
|
return res;
|
|
506
502
|
}
|
|
507
503
|
catch (e) {
|
|
508
|
-
|
|
509
|
-
logger_1.default.error(`rabbit sendToQueue: failed to send to queue ${queue}, isConnected: ${isConnected}`, { e });
|
|
504
|
+
logger_1.default.error(`rabbit sendToQueue: failed to send to queue ${queue}`, { e });
|
|
510
505
|
throw e;
|
|
511
506
|
}
|
|
512
507
|
}
|
|
513
|
-
async isConnected(
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
logger_1.default.
|
|
533
|
-
return
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
return true;
|
|
508
|
+
async isConnected() {
|
|
509
|
+
const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
510
|
+
const { connection } = connectionData;
|
|
511
|
+
const isConnected = connection?.isConnected();
|
|
512
|
+
if (!isConnected) {
|
|
513
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
|
|
517
|
+
try {
|
|
518
|
+
await Promise.all([
|
|
519
|
+
channel.waitForConnect(),
|
|
520
|
+
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
521
|
+
]);
|
|
522
|
+
}
|
|
523
|
+
catch (e) {
|
|
524
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
logger_1.default.info('rabbit: isConnected - true');
|
|
528
|
+
return true;
|
|
529
|
+
}));
|
|
530
|
+
return isEachConnectionConnected.every((isConnected) => isConnected === true);
|
|
537
531
|
}
|
|
538
532
|
async gracefulShutdown(signal) {
|
|
539
533
|
const tagsNumber = this.consumersTags.length;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -83,7 +83,7 @@ type newChannelOpts = {
|
|
|
83
83
|
name?: string;
|
|
84
84
|
onClose?: null | ((args: any | null) => void);
|
|
85
85
|
options?: CreateChannelOpts | undefined;
|
|
86
|
-
connectionPurpose
|
|
86
|
+
connectionPurpose?: ConnectionPurpose,
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
type assertChannelOpts = {
|
|
@@ -321,11 +321,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
321
321
|
findServers,
|
|
322
322
|
});
|
|
323
323
|
|
|
324
|
-
if (!newConnection) {
|
|
325
|
-
logger.error('rabbit: couldnt create a connection');
|
|
326
|
-
return resolve(connection);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
324
|
this.connectionsMap[connectionPurpose].connection = newConnection;
|
|
330
325
|
|
|
331
326
|
newConnection.on('error', (err) => {
|
|
@@ -638,7 +633,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
638
633
|
RabbitMq.validateName('queue', queue);
|
|
639
634
|
const { limit, deadMessageTtl } = optionsWithDefaults;
|
|
640
635
|
await this.saveConsumer(queue, callback, options);
|
|
641
|
-
const channel: ChannelWrapper = await this.getNewChannel({ name: `consume - exchange - ${exchange} -queue - ${queue}
|
|
636
|
+
const channel: ChannelWrapper = await this.getNewChannel({ name: `consume - exchange - ${exchange} -queue - ${queue}` });
|
|
642
637
|
|
|
643
638
|
return channel.addSetup(async (c: ConfirmChannel) => {
|
|
644
639
|
const assertExchange = await assertExchangeFanout(c, exchange);
|
|
@@ -695,35 +690,35 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
695
690
|
debug(`rabbit: sending to queue ${queue}`, { res });
|
|
696
691
|
return res;
|
|
697
692
|
} catch (e) {
|
|
698
|
-
|
|
699
|
-
logger.error(`rabbit sendToQueue: failed to send to queue ${queue}, isConnected: ${isConnected}`, { e });
|
|
693
|
+
logger.error(`rabbit sendToQueue: failed to send to queue ${queue}`, { e });
|
|
700
694
|
throw e;
|
|
701
695
|
}
|
|
702
696
|
}
|
|
703
697
|
|
|
704
|
-
async isConnected(
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
698
|
+
async isConnected(): Promise<boolean> {
|
|
699
|
+
const isEachConnectionConnected = await Promise.all(
|
|
700
|
+
Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
701
|
+
const { connection } = connectionData;
|
|
702
|
+
const isConnected = connection?.isConnected();
|
|
703
|
+
if (!isConnected) {
|
|
704
|
+
logger.error('rabbit: isConnected - false');
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
const channel: any = await this.assertChannel({ connectionPurpose: connectionPurpose as ConnectionPurpose });
|
|
708
|
+
try {
|
|
709
|
+
await Promise.all([
|
|
710
|
+
channel.waitForConnect(),
|
|
711
|
+
...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
712
|
+
]);
|
|
713
|
+
} catch (e) {
|
|
714
|
+
logger.error('rabbit: isConnected - false');
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
logger.info('rabbit: isConnected - true');
|
|
718
|
+
return true;
|
|
719
|
+
}),
|
|
720
|
+
);
|
|
721
|
+
return isEachConnectionConnected.every((isConnected) => isConnected === true);
|
|
727
722
|
}
|
|
728
723
|
|
|
729
724
|
async gracefulShutdown(signal: string): Promise<void> {
|