@autofleet/rabbit 3.2.26-beta.200 → 3.2.26-beta.201

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 CHANGED
@@ -132,6 +132,7 @@ class RabbitMq {
132
132
  creatingConnection: false,
133
133
  connectionCreatedEventName: 'publishConnectionCreated',
134
134
  connectionFailedEventName: 'publishConnectionFailed',
135
+ doesChannelInitialize: false,
135
136
  },
136
137
  };
137
138
  this.exchanges = {};
@@ -275,6 +276,7 @@ class RabbitMq {
275
276
  });
276
277
  if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
277
278
  this.publishChannel = channel;
279
+ this.connectionsMap[connectionPurpose].doesChannelInitialize = true;
278
280
  }
279
281
  resolve(channel);
280
282
  }
@@ -566,7 +568,16 @@ class RabbitMq {
566
568
  async isConnected() {
567
569
  debug('rabbit: start is connected');
568
570
  const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
569
- if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
571
+ const { connection, doesChannelInitialize } = connectionData;
572
+ if (connectionPurpose === consts_1.ConnectionPurpose.Consume
573
+ || (connectionPurpose === consts_1.ConnectionPurpose.Publish
574
+ && doesChannelInitialize)) {
575
+ debug('rabbit: is connected inside map', { connection, connectionPurpose });
576
+ const isConnected = connection?.isConnected();
577
+ if (!isConnected) {
578
+ logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
579
+ return false;
580
+ }
570
581
  const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
571
582
  try {
572
583
  await Promise.all([
@@ -579,13 +590,6 @@ class RabbitMq {
579
590
  return false;
580
591
  }
581
592
  }
582
- const { connection } = connectionData;
583
- debug('rabbit: is connected inside map', { connection, connectionPurpose });
584
- const isConnected = connection?.isConnected();
585
- if (!isConnected) {
586
- logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
587
- return false;
588
- }
589
593
  logger_1.default.info('rabbit: isConnected - true');
590
594
  return true;
591
595
  }));
@@ -56,4 +56,5 @@ export type ConnectionData = {
56
56
  creatingConnection: boolean;
57
57
  connectionCreatedEventName: string;
58
58
  connectionFailedEventName: string;
59
+ doesChannelInitialize?: boolean;
59
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.2.26-beta.200",
3
+ "version": "3.2.26-beta.201",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
package/src/index.ts CHANGED
@@ -183,6 +183,7 @@ class RabbitMq implements IAfRabbitMq {
183
183
  creatingConnection: false,
184
184
  connectionCreatedEventName: 'publishConnectionCreated',
185
185
  connectionFailedEventName: 'publishConnectionFailed',
186
+ doesChannelInitialize: false,
186
187
  },
187
188
  };
188
189
  this.exchanges = {};
@@ -417,6 +418,7 @@ class RabbitMq implements IAfRabbitMq {
417
418
  });
418
419
  if (connectionPurpose === ConnectionPurpose.Publish) {
419
420
  this.publishChannel = channel;
421
+ this.connectionsMap[connectionPurpose].doesChannelInitialize = true;
420
422
  }
421
423
  resolve(channel);
422
424
  } catch (e) {
@@ -761,7 +763,18 @@ class RabbitMq implements IAfRabbitMq {
761
763
  debug('rabbit: start is connected');
762
764
  const isEachConnectionConnected = await Promise.all(
763
765
  Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
764
- if (connectionPurpose === ConnectionPurpose.Publish) {
766
+ const { connection, doesChannelInitialize } = connectionData;
767
+ if (
768
+ connectionPurpose === ConnectionPurpose.Consume
769
+ || (connectionPurpose === ConnectionPurpose.Publish
770
+ && doesChannelInitialize
771
+ )) {
772
+ debug('rabbit: is connected inside map', { connection, connectionPurpose });
773
+ const isConnected = connection?.isConnected();
774
+ if (!isConnected) {
775
+ logger.error('rabbit: isConnected - false', { connectionPurpose });
776
+ return false;
777
+ }
765
778
  const channel: any = await this.assertChannel({ connectionPurpose: connectionPurpose as ConnectionPurpose });
766
779
  try {
767
780
  await Promise.all([
@@ -773,13 +786,6 @@ class RabbitMq implements IAfRabbitMq {
773
786
  return false;
774
787
  }
775
788
  }
776
- const { connection } = connectionData;
777
- debug('rabbit: is connected inside map', { connection, connectionPurpose });
778
- const isConnected = connection?.isConnected();
779
- if (!isConnected) {
780
- logger.error('rabbit: isConnected - false', { connectionPurpose });
781
- return false;
782
- }
783
789
  logger.info('rabbit: isConnected - true');
784
790
  return true;
785
791
  }),
package/src/lib/types.ts CHANGED
@@ -76,4 +76,5 @@ export type ConnectionData = {
76
76
  creatingConnection: boolean;
77
77
  connectionCreatedEventName: string;
78
78
  connectionFailedEventName: string;
79
+ doesChannelInitialize?: boolean;
79
80
  };