@autofleet/rabbit 3.2.22-beta.2 → 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 CHANGED
@@ -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(connectionPurpose: ConnectionPurpose): Promise<boolean>;
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,33 @@ class RabbitMq {
501
501
  return res;
502
502
  }
503
503
  catch (e) {
504
- const isConnected = await this.isConnected(types_1.ConnectionPurpose.Publish);
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(connectionPurpose) {
510
- const connection = await this.getConnection(connectionPurpose);
511
- if (!connection) {
512
- logger_1.default.error('rabbit: isConnected - false');
513
- return false;
514
- }
515
- const isConnected = connection.isConnected();
516
- if (!isConnected) {
517
- logger_1.default.error('rabbit: isConnected - false');
518
- return false;
519
- }
520
- const channel = await this.assertChannel({ connectionPurpose });
521
- try {
522
- await Promise.all([
523
- channel.waitForConnect(),
524
- ...this.consumers.map((c) => channel.checkQueue(c.queue)),
525
- ]);
526
- }
527
- catch (e) {
528
- logger_1.default.error('rabbit: isConnected - false');
529
- return false;
530
- }
531
- logger_1.default.info('rabbit: isConnected - true');
532
- 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);
533
531
  }
534
532
  async gracefulShutdown(signal) {
535
533
  const tagsNumber = this.consumersTags.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.2.22-beta.2",
3
+ "version": "3.2.22-beta.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -690,35 +690,35 @@ class RabbitMq implements IAfRabbitMq {
690
690
  debug(`rabbit: sending to queue ${queue}`, { res });
691
691
  return res;
692
692
  } catch (e) {
693
- const isConnected = await this.isConnected(ConnectionPurpose.Publish);
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(connectionPurpose: ConnectionPurpose): Promise<boolean> {
700
- const connection = await this.getConnection(connectionPurpose);
701
- if (!connection) {
702
- logger.error('rabbit: isConnected - false');
703
- return false;
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 });
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;
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);
722
722
  }
723
723
 
724
724
  async gracefulShutdown(signal: string): Promise<void> {