@autofleet/rabbit 3.3.0-beta.2 → 3.3.0-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 CHANGED
@@ -62,7 +62,6 @@ declare class RabbitMq implements IAfRabbitMq {
62
62
  RECONNECT_MSG: string;
63
63
  publishChannel: ChannelWrapper | null;
64
64
  publishChannelSetupPromise: Promise<ChannelWrapper> | null;
65
- blockReconnect: boolean | null | undefined;
66
65
  connectionsMap: {
67
66
  [ConnectionPurpose.Consume]: ConnectionData;
68
67
  [ConnectionPurpose.Publish]: ConnectionData;
package/dist/index.js CHANGED
@@ -125,12 +125,14 @@ class RabbitMq {
125
125
  creatingConnection: false,
126
126
  connectionCreatedEventName: 'consumeConnectionCreated',
127
127
  connectionFailedEventName: 'consumeConnectionFailed',
128
+ blockReconnect: false,
128
129
  },
129
130
  [consts_1.ConnectionPurpose.Publish]: {
130
131
  connection: null,
131
132
  creatingConnection: false,
132
133
  connectionCreatedEventName: 'publishConnectionCreated',
133
134
  connectionFailedEventName: 'publishConnectionFailed',
135
+ blockReconnect: false,
134
136
  },
135
137
  };
136
138
  this.exchanges = {};
@@ -156,8 +158,8 @@ class RabbitMq {
156
158
  }
157
159
  async getConnection(connectionPurpose) {
158
160
  return new Promise(async (resolve, reject) => {
159
- const { connection, creatingConnection, connectionCreatedEventName, connectionFailedEventName, } = this.connectionsMap[connectionPurpose];
160
- if (this.blockReconnect) {
161
+ const { connection, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = this.connectionsMap[connectionPurpose];
162
+ if (blockReconnect) {
161
163
  debug('rabbit: block reconnect');
162
164
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
163
165
  // @ts-ignore
@@ -218,7 +220,7 @@ class RabbitMq {
218
220
  debug('rabbit: connection closed');
219
221
  if (this.options?.disableReconnect) {
220
222
  logger_1.default.error(`${this.DISCONNECT_MSG}${err && ` - ${err}`}`);
221
- this.blockReconnect = true;
223
+ this.connectionsMap[connectionPurpose].blockReconnect = true;
222
224
  }
223
225
  else {
224
226
  logger_1.default.error(`${this.RECONNECT_MSG}${err && ` - ${err}`}`);
@@ -556,14 +558,13 @@ class RabbitMq {
556
558
  }
557
559
  async isConnected() {
558
560
  debug('rabbit: start is connected');
559
- const isEachConnectionConnected = await Promise.all(Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
560
- const { connection } = connectionData;
561
+ const isEachConnectionConnected = await Promise.all(Object.keys(this.connectionsMap).map(async (connectionPurpose) => {
562
+ const connection = await this.getConnection(connectionPurpose);
561
563
  const isConnected = connection?.isConnected();
562
564
  if (!isConnected) {
563
565
  logger_1.default.error('rabbit: isConnected - false', { connectionPurpose });
564
566
  return false;
565
567
  }
566
- logger_1.default.info('rabbit: isConnected - true', { connectionPurpose });
567
568
  if (connectionPurpose === consts_1.ConnectionPurpose.Publish) {
568
569
  const channel = await this.assertChannel({ connectionPurpose: connectionPurpose });
569
570
  try {
@@ -577,6 +578,7 @@ class RabbitMq {
577
578
  return false;
578
579
  }
579
580
  }
581
+ logger_1.default.info('rabbit: isConnected - true', { connectionPurpose });
580
582
  return true;
581
583
  }));
582
584
  return isEachConnectionConnected.every((isConnected) => isConnected === true);
@@ -47,4 +47,5 @@ export type ConnectionData = {
47
47
  creatingConnection: boolean;
48
48
  connectionCreatedEventName: string;
49
49
  connectionFailedEventName: string;
50
+ blockReconnect: boolean;
50
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.3.0-beta.2",
3
+ "version": "3.3.0-beta.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
package/src/index.ts CHANGED
@@ -148,8 +148,6 @@ class RabbitMq implements IAfRabbitMq {
148
148
 
149
149
  publishChannelSetupPromise: Promise<ChannelWrapper> | null;
150
150
 
151
- blockReconnect: boolean | null | undefined;
152
-
153
151
  connectionsMap: {
154
152
  [ConnectionPurpose.Consume]: ConnectionData;
155
153
  [ConnectionPurpose.Publish]: ConnectionData;
@@ -186,12 +184,14 @@ class RabbitMq implements IAfRabbitMq {
186
184
  creatingConnection: false,
187
185
  connectionCreatedEventName: 'consumeConnectionCreated',
188
186
  connectionFailedEventName: 'consumeConnectionFailed',
187
+ blockReconnect: false,
189
188
  },
190
189
  [ConnectionPurpose.Publish]: {
191
190
  connection: null,
192
191
  creatingConnection: false,
193
192
  connectionCreatedEventName: 'publishConnectionCreated',
194
193
  connectionFailedEventName: 'publishConnectionFailed',
194
+ blockReconnect: false,
195
195
  },
196
196
  };
197
197
  this.exchanges = {};
@@ -298,8 +298,10 @@ class RabbitMq implements IAfRabbitMq {
298
298
  creatingConnection,
299
299
  connectionCreatedEventName,
300
300
  connectionFailedEventName,
301
+ blockReconnect,
301
302
  } = this.connectionsMap[connectionPurpose];
302
- if (this.blockReconnect) {
303
+
304
+ if (blockReconnect) {
303
305
  debug('rabbit: block reconnect');
304
306
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
305
307
  // @ts-ignore
@@ -368,7 +370,7 @@ class RabbitMq implements IAfRabbitMq {
368
370
  debug('rabbit: connection closed');
369
371
  if (this.options?.disableReconnect) {
370
372
  logger.error(`${this.DISCONNECT_MSG}${err && ` - ${err}`}`);
371
- this.blockReconnect = true;
373
+ this.connectionsMap[connectionPurpose].blockReconnect = true;
372
374
  } else {
373
375
  logger.error(`${this.RECONNECT_MSG}${err && ` - ${err}`}`);
374
376
  }
@@ -761,14 +763,13 @@ class RabbitMq implements IAfRabbitMq {
761
763
  async isConnected(): Promise<boolean> {
762
764
  debug('rabbit: start is connected');
763
765
  const isEachConnectionConnected = await Promise.all(
764
- Object.entries(this.connectionsMap).map(async ([connectionPurpose, connectionData]) => {
765
- const { connection } = connectionData;
766
+ Object.keys(this.connectionsMap).map(async (connectionPurpose) => {
767
+ const connection = await this.getConnection(connectionPurpose as ConnectionPurpose);
766
768
  const isConnected = connection?.isConnected();
767
769
  if (!isConnected) {
768
770
  logger.error('rabbit: isConnected - false', { connectionPurpose });
769
771
  return false;
770
772
  }
771
- logger.info('rabbit: isConnected - true', { connectionPurpose });
772
773
 
773
774
  if (connectionPurpose === ConnectionPurpose.Publish) {
774
775
  const channel: any = await this.assertChannel({ connectionPurpose: connectionPurpose as ConnectionPurpose });
@@ -782,7 +783,7 @@ class RabbitMq implements IAfRabbitMq {
782
783
  return false;
783
784
  }
784
785
  }
785
-
786
+ logger.info('rabbit: isConnected - true', { connectionPurpose });
786
787
  return true;
787
788
  }),
788
789
  );
package/src/lib/types.ts CHANGED
@@ -66,4 +66,5 @@ export type ConnectionData = {
66
66
  creatingConnection: boolean;
67
67
  connectionCreatedEventName: string;
68
68
  connectionFailedEventName: string;
69
+ blockReconnect: boolean;
69
70
  };