@autofleet/rabbit 3.4.0-beta.17 → 3.4.0-beta.18

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
@@ -168,14 +168,14 @@ class RabbitMq {
168
168
  this.publishChannelSetupPromise = null;
169
169
  this.connection = null;
170
170
  this.publishConnection = {
171
- connection: null,
171
+ amqpConnection: null,
172
172
  creatingConnection: false,
173
173
  connectionCreatedEventName: 'publishConnectionCreated',
174
174
  connectionFailedEventName: 'publishConnectionFailed',
175
175
  blockReconnect: false,
176
176
  };
177
177
  this.consumeConnection = {
178
- connection: null,
178
+ amqpConnection: null,
179
179
  creatingConnection: false,
180
180
  connectionCreatedEventName: 'consumeConnectionCreated',
181
181
  connectionFailedEventName: 'consumeConnectionFailed',
@@ -207,14 +207,14 @@ class RabbitMq {
207
207
  this.oldPublishChannel = null;
208
208
  this.oldPublishChannelSetupPromise = null;
209
209
  this.oldPublishConnection = {
210
- connection: null,
210
+ amqpConnection: null,
211
211
  creatingConnection: false,
212
212
  connectionCreatedEventName: 'oldPublishConnectionCreated',
213
213
  connectionFailedEventName: 'oldPublishConnectionFailed',
214
214
  blockReconnect: false,
215
215
  };
216
216
  this.oldConsumeConnection = {
217
- connection: null,
217
+ amqpConnection: null,
218
218
  creatingConnection: false,
219
219
  connectionCreatedEventName: 'oldConsumeConnectionCreated',
220
220
  connectionFailedEventName: 'oldConsumeConnectionFailed',
@@ -230,7 +230,7 @@ class RabbitMq {
230
230
  }
231
231
  async getConnection(connection) {
232
232
  return new Promise(async (resolve, reject) => {
233
- const { connection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
233
+ const { amqpConnection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
234
234
  if (blockReconnect) {
235
235
  debug('rabbit: block reconnect');
236
236
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -268,7 +268,7 @@ class RabbitMq {
268
268
  const newConnection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
269
269
  findServers,
270
270
  });
271
- connection.connection = newConnection;
271
+ connection.amqpConnection = newConnection;
272
272
  newConnection.on('error', (err) => {
273
273
  logger_1.default.error('rabbit: connection error', { err });
274
274
  if (!isResolved) {
@@ -374,7 +374,7 @@ class RabbitMq {
374
374
  if (!channel) {
375
375
  throw new rabbitError_1.default('channel is not defined');
376
376
  }
377
- debug('rabbit: getting queue length', { queue, connected: this.connection?.isConnected() });
377
+ debug('rabbit: getting queue length', { queue, connected: this.oldPublishConnection.amqpConnection?.isConnected() });
378
378
  return channel?.checkQueue(queue);
379
379
  }
380
380
  async deleteQueue(queue, connection) {
@@ -669,7 +669,6 @@ class RabbitMq {
669
669
  }
670
670
  // TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
671
671
  async isConnected() {
672
- // TODO: OLD IMPLEMENTATION
673
672
  debug('rabbit: start old is connected');
674
673
  const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
675
674
  const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
@@ -690,27 +689,6 @@ class RabbitMq {
690
689
  return false;
691
690
  }
692
691
  logger_1.default.debug('rabbit: old isConnected - true');
693
- // TODO: NEW IMPLEMENTATION
694
- debug('rabbit: start is connected');
695
- const consumeConnection = await this.getConnection(this.consumeConnection);
696
- const publishConnection = await this.getConnection(this.publishConnection);
697
- const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
698
- if (!isConnected) {
699
- logger_1.default.error('rabbit: isConnected - false');
700
- return false;
701
- }
702
- const channel = await this.assertChannel({ connection: this.publishConnection });
703
- try {
704
- await Promise.all([
705
- channel.waitForConnect(),
706
- ...this.consumers.map((c) => channel.checkQueue(c.queue)),
707
- ]);
708
- }
709
- catch (e) {
710
- logger_1.default.error('rabbit: isConnected - false');
711
- return false;
712
- }
713
- logger_1.default.debug('rabbit: isConnected - true');
714
692
  return true;
715
693
  }
716
694
  async gracefulShutdown(signal) {
@@ -851,7 +829,7 @@ class RabbitMq {
851
829
  }
852
830
  async getConnectionOld(connection) {
853
831
  return new Promise(async (resolve, reject) => {
854
- const { connection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
832
+ const { amqpConnection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
855
833
  if (blockReconnect) {
856
834
  debug('rabbit: block reconnect');
857
835
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -889,7 +867,7 @@ class RabbitMq {
889
867
  const newConnection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
890
868
  findServers,
891
869
  });
892
- connection.connection = newConnection;
870
+ connection.amqpConnection = newConnection;
893
871
  newConnection.on('error', (err) => {
894
872
  logger_1.default.error('rabbit: connection error', { err });
895
873
  if (!isResolved) {
@@ -44,7 +44,7 @@ export type AfConsumer = {
44
44
  };
45
45
  export declare const CONSUMER_DEFAULT_OPTIONS: Options.Consume;
46
46
  export type ConnectionData = {
47
- connection: AmqpConnectionManager | null;
47
+ amqpConnection: AmqpConnectionManager | null;
48
48
  creatingConnection: boolean;
49
49
  connectionCreatedEventName: string;
50
50
  connectionFailedEventName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.4.0-beta.17",
3
+ "version": "3.4.0-beta.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
package/src/index.ts CHANGED
@@ -215,14 +215,14 @@ class RabbitMq implements IAfRabbitMq {
215
215
  this.publishChannelSetupPromise = null;
216
216
  this.connection = null;
217
217
  this.publishConnection = {
218
- connection: null,
218
+ amqpConnection: null,
219
219
  creatingConnection: false,
220
220
  connectionCreatedEventName: 'publishConnectionCreated',
221
221
  connectionFailedEventName: 'publishConnectionFailed',
222
222
  blockReconnect: false,
223
223
  };
224
224
  this.consumeConnection = {
225
- connection: null,
225
+ amqpConnection: null,
226
226
  creatingConnection: false,
227
227
  connectionCreatedEventName: 'consumeConnectionCreated',
228
228
  connectionFailedEventName: 'consumeConnectionFailed',
@@ -256,14 +256,14 @@ class RabbitMq implements IAfRabbitMq {
256
256
  this.oldPublishChannel = null;
257
257
  this.oldPublishChannelSetupPromise = null;
258
258
  this.oldPublishConnection = {
259
- connection: null,
259
+ amqpConnection: null,
260
260
  creatingConnection: false,
261
261
  connectionCreatedEventName: 'oldPublishConnectionCreated',
262
262
  connectionFailedEventName: 'oldPublishConnectionFailed',
263
263
  blockReconnect: false,
264
264
  };
265
265
  this.oldConsumeConnection = {
266
- connection: null,
266
+ amqpConnection: null,
267
267
  creatingConnection: false,
268
268
  connectionCreatedEventName: 'oldConsumeConnectionCreated',
269
269
  connectionFailedEventName: 'oldConsumeConnectionFailed',
@@ -409,7 +409,7 @@ class RabbitMq implements IAfRabbitMq {
409
409
  async getConnection(connection: ConnectionData) {
410
410
  return new Promise<AmqpConnectionManager>(async (resolve, reject) => {
411
411
  const {
412
- connection: connectionLocal,
412
+ amqpConnection: connectionLocal,
413
413
  creatingConnection,
414
414
  connectionCreatedEventName,
415
415
  connectionFailedEventName,
@@ -457,7 +457,7 @@ class RabbitMq implements IAfRabbitMq {
457
457
  findServers,
458
458
  });
459
459
 
460
- connection.connection = newConnection;
460
+ connection.amqpConnection = newConnection;
461
461
  newConnection.on('error', (err) => {
462
462
  logger.error('rabbit: connection error', { err });
463
463
  if (!isResolved) {
@@ -572,7 +572,7 @@ class RabbitMq implements IAfRabbitMq {
572
572
  if (!channel) {
573
573
  throw new RabbitError('channel is not defined');
574
574
  }
575
- debug('rabbit: getting queue length', { queue, connected: this.connection?.isConnected() });
575
+ debug('rabbit: getting queue length', { queue, connected: this.oldPublishConnection.amqpConnection?.isConnected() });
576
576
  return channel?.checkQueue(queue);
577
577
  }
578
578
 
@@ -922,8 +922,7 @@ class RabbitMq implements IAfRabbitMq {
922
922
  }
923
923
 
924
924
  // TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
925
- async isConnected() : Promise<boolean> {
926
- // TODO: OLD IMPLEMENTATION
925
+ async isConnected(): Promise<boolean> {
927
926
  debug('rabbit: start old is connected');
928
927
  const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
929
928
  const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
@@ -943,27 +942,6 @@ class RabbitMq implements IAfRabbitMq {
943
942
  return false;
944
943
  }
945
944
  logger.debug('rabbit: old isConnected - true');
946
-
947
- // TODO: NEW IMPLEMENTATION
948
- debug('rabbit: start is connected');
949
- const consumeConnection = await this.getConnection(this.consumeConnection);
950
- const publishConnection = await this.getConnection(this.publishConnection);
951
- const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
952
- if (!isConnected) {
953
- logger.error('rabbit: isConnected - false');
954
- return false;
955
- }
956
- const channel: any = await this.assertChannel({ connection: this.publishConnection });
957
- try {
958
- await Promise.all([
959
- channel.waitForConnect(),
960
- ...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
961
- ]);
962
- } catch (e) {
963
- logger.error('rabbit: isConnected - false');
964
- return false;
965
- }
966
- logger.debug('rabbit: isConnected - true');
967
945
  return true;
968
946
  }
969
947
 
@@ -1123,7 +1101,7 @@ class RabbitMq implements IAfRabbitMq {
1123
1101
  async getConnectionOld(connection: ConnectionData) {
1124
1102
  return new Promise<AmqpConnectionManager>(async (resolve, reject) => {
1125
1103
  const {
1126
- connection: connectionLocal,
1104
+ amqpConnection: connectionLocal,
1127
1105
  creatingConnection,
1128
1106
  connectionCreatedEventName,
1129
1107
  connectionFailedEventName,
@@ -1172,7 +1150,7 @@ class RabbitMq implements IAfRabbitMq {
1172
1150
  findServers,
1173
1151
  });
1174
1152
 
1175
- connection.connection = newConnection;
1153
+ connection.amqpConnection = newConnection;
1176
1154
  newConnection.on('error', (err) => {
1177
1155
  logger.error('rabbit: connection error', { err });
1178
1156
  if (!isResolved) {
package/src/lib/types.ts CHANGED
@@ -64,7 +64,7 @@ export const CONSUMER_DEFAULT_OPTIONS: Options.Consume = {
64
64
  };
65
65
 
66
66
  export type ConnectionData = {
67
- connection: AmqpConnectionManager | null;
67
+ amqpConnection: AmqpConnectionManager | null;
68
68
  creatingConnection: boolean;
69
69
  connectionCreatedEventName: string;
70
70
  connectionFailedEventName: string;