@autofleet/rabbit 3.2.22-beta.2 → 3.2.22-beta.4
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 +27 -26
- package/package.json +1 -1
- package/src/index.ts +29 -26
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ type newChannelOpts = {
|
|
|
42
42
|
type assertChannelOpts = {
|
|
43
43
|
channelName?: string;
|
|
44
44
|
force?: boolean;
|
|
45
|
-
connectionPurpose
|
|
45
|
+
connectionPurpose?: ConnectionPurpose;
|
|
46
46
|
};
|
|
47
47
|
declare class RabbitMq implements IAfRabbitMq {
|
|
48
48
|
static parseMsg(msg: any): any;
|
|
@@ -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
|
@@ -501,35 +501,36 @@ class RabbitMq {
|
|
|
501
501
|
return res;
|
|
502
502
|
}
|
|
503
503
|
catch (e) {
|
|
504
|
-
|
|
505
|
-
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 });
|
|
506
505
|
throw e;
|
|
507
506
|
}
|
|
508
507
|
}
|
|
509
|
-
async isConnected(
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
508
|
+
async isConnected() {
|
|
509
|
+
const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
|
|
510
|
+
const { connection } = connectionData;
|
|
511
|
+
if (connectionPurpose === types_1.ConnectionPurpose.Publish && !connection) {
|
|
512
|
+
return true; // The connection hasn't been initialized yet, as no messages have been sent through it
|
|
513
|
+
}
|
|
514
|
+
const isConnected = connection?.isConnected();
|
|
515
|
+
if (!isConnected) {
|
|
516
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
|
|
520
|
+
try {
|
|
521
|
+
await Promise.all([
|
|
522
|
+
channel.waitForConnect(),
|
|
523
|
+
...this.consumers.map((c) => channel.checkQueue(c.queue)),
|
|
524
|
+
]);
|
|
525
|
+
}
|
|
526
|
+
catch (e) {
|
|
527
|
+
logger_1.default.error('rabbit: isConnected - false');
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
logger_1.default.info('rabbit: isConnected - true');
|
|
531
|
+
return true;
|
|
532
|
+
}));
|
|
533
|
+
return isEachConnectionConnected.every((isConnected) => isConnected === true);
|
|
533
534
|
}
|
|
534
535
|
async gracefulShutdown(signal) {
|
|
535
536
|
const tagsNumber = this.consumersTags.length;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -89,7 +89,7 @@ type newChannelOpts = {
|
|
|
89
89
|
type assertChannelOpts = {
|
|
90
90
|
channelName?: string;
|
|
91
91
|
force?: boolean;
|
|
92
|
-
connectionPurpose
|
|
92
|
+
connectionPurpose?: ConnectionPurpose;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
type AfConsumer = {
|
|
@@ -690,35 +690,38 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
690
690
|
debug(`rabbit: sending to queue ${queue}`, { res });
|
|
691
691
|
return res;
|
|
692
692
|
} catch (e) {
|
|
693
|
-
|
|
694
|
-
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 });
|
|
695
694
|
throw e;
|
|
696
695
|
}
|
|
697
696
|
}
|
|
698
697
|
|
|
699
|
-
async isConnected(
|
|
700
|
-
const
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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
|
+
if (connectionPurpose === ConnectionPurpose.Publish && !connection) {
|
|
703
|
+
return true; // The connection hasn't been initialized yet, as no messages have been sent through it
|
|
704
|
+
}
|
|
705
|
+
const isConnected = connection?.isConnected();
|
|
706
|
+
if (!isConnected) {
|
|
707
|
+
logger.error('rabbit: isConnected - false');
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
const channel: any = await this.assertChannel({ connectionPurpose: connectionPurpose as ConnectionPurpose });
|
|
711
|
+
try {
|
|
712
|
+
await Promise.all([
|
|
713
|
+
channel.waitForConnect(),
|
|
714
|
+
...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
715
|
+
]);
|
|
716
|
+
} catch (e) {
|
|
717
|
+
logger.error('rabbit: isConnected - false');
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
logger.info('rabbit: isConnected - true');
|
|
721
|
+
return true;
|
|
722
|
+
}),
|
|
723
|
+
);
|
|
724
|
+
return isEachConnectionConnected.every((isConnected) => isConnected === true);
|
|
722
725
|
}
|
|
723
726
|
|
|
724
727
|
async gracefulShutdown(signal: string): Promise<void> {
|