@autofleet/rabbit 3.4.0-beta.16 → 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,13 +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;
234
- if (connection === this.publishConnection) {
235
- debug('rabbit: getConnection publish', { connectionLocal, creatingConnection, blockReconnect });
236
- }
237
- else if (connection === this.consumeConnection) {
238
- debug('rabbit: getConnection consume', { connectionLocal, creatingConnection, blockReconnect });
239
- }
233
+ const { amqpConnection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
240
234
  if (blockReconnect) {
241
235
  debug('rabbit: block reconnect');
242
236
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -244,12 +238,6 @@ class RabbitMq {
244
238
  return resolve();
245
239
  }
246
240
  if (connectionLocal !== null) {
247
- if (connection === this.publishConnection) {
248
- debug('rabbit: getConnection publish getConnection is not null', { connectionLocal });
249
- }
250
- else if (connection === this.consumeConnection) {
251
- debug('rabbit: getConnection consume getConnection is not null', { connectionLocal });
252
- }
253
241
  if (this.options?.disableReconnect || connectionLocal?.isConnected()) {
254
242
  debug('rabbit: connection - is connected');
255
243
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -280,13 +268,7 @@ class RabbitMq {
280
268
  const newConnection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
281
269
  findServers,
282
270
  });
283
- connection.connection = newConnection;
284
- if (connection === this.publishConnection) {
285
- debug('rabbit: publishConnection set');
286
- }
287
- else if (connection === this.consumeConnection) {
288
- debug('rabbit: consumeConnection set');
289
- }
271
+ connection.amqpConnection = newConnection;
290
272
  newConnection.on('error', (err) => {
291
273
  logger_1.default.error('rabbit: connection error', { err });
292
274
  if (!isResolved) {
@@ -334,12 +316,6 @@ class RabbitMq {
334
316
  logger_1.default.error(`rabbit: error on get connection for new channel ${name} `, { e });
335
317
  throw e;
336
318
  }
337
- if (connection === this.publishConnection) {
338
- debug('rabbit: getNewChannel publish', { localConnection });
339
- }
340
- else if (connection === this.consumeConnection) {
341
- debug('rabbit: getNewChannel consume', { localConnection });
342
- }
343
319
  const channel = localConnection?.createChannel({ ...options });
344
320
  (0, events_1.once)(channel, 'close').then((args) => {
345
321
  logger_1.default.error(`rabbit: channel ${name} closed`);
@@ -356,15 +332,6 @@ class RabbitMq {
356
332
  }
357
333
  }
358
334
  async assertChannel({ force = false, connection }) {
359
- if (connection === this.publishConnection) {
360
- debug('rabbit: assertChannel publish', { force, promiseSetup: this.oldPublishChannelSetupPromise });
361
- }
362
- else if (connection === this.consumeConnection) {
363
- debug('rabbit: assertChannel consume', { force, promiseSetup: this.oldPublishChannelSetupPromise });
364
- }
365
- else {
366
- debug('rabbit: assertChannel with undefined connection', { force, promiseSetup: this.oldPublishChannelSetupPromise, connection });
367
- }
368
335
  if (!this.publishChannelSetupPromise) {
369
336
  this.publishChannelSetupPromise = new Promise(async (resolve, reject) => {
370
337
  if (this.publishChannel && !force) {
@@ -407,7 +374,7 @@ class RabbitMq {
407
374
  if (!channel) {
408
375
  throw new rabbitError_1.default('channel is not defined');
409
376
  }
410
- debug('rabbit: getting queue length', { queue, connected: this.connection?.isConnected() });
377
+ debug('rabbit: getting queue length', { queue, connected: this.oldPublishConnection.amqpConnection?.isConnected() });
411
378
  return channel?.checkQueue(queue);
412
379
  }
413
380
  async deleteQueue(queue, connection) {
@@ -702,13 +669,12 @@ class RabbitMq {
702
669
  }
703
670
  // TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
704
671
  async isConnected() {
705
- // TODO: OLD IMPLEMENTATION
706
672
  debug('rabbit: start old is connected');
707
673
  const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
708
674
  const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
709
675
  const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
710
676
  if (!oldIsConnected) {
711
- logger_1.default.error('rabbit: isConnected - false');
677
+ logger_1.default.error('rabbit: old isConnected - false');
712
678
  return false;
713
679
  }
714
680
  const oldChannel = await this.assertChannelOld({ connection: this.oldPublishConnection });
@@ -719,31 +685,10 @@ class RabbitMq {
719
685
  ]);
720
686
  }
721
687
  catch (e) {
722
- logger_1.default.error('rabbit: isConnected - false');
688
+ logger_1.default.error('rabbit: old isConnected - false');
723
689
  return false;
724
690
  }
725
691
  logger_1.default.debug('rabbit: old isConnected - true');
726
- // TODO: NEW IMPLEMENTATION
727
- debug('rabbit: start is connected');
728
- const consumeConnection = await this.getConnection(this.consumeConnection);
729
- const publishConnection = await this.getConnection(this.publishConnection);
730
- const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
731
- if (!isConnected) {
732
- logger_1.default.error('rabbit: isConnected - false');
733
- return false;
734
- }
735
- const channel = await this.assertChannel({ connection: this.publishConnection });
736
- try {
737
- await Promise.all([
738
- channel.waitForConnect(),
739
- ...this.consumers.map((c) => channel.checkQueue(c.queue)),
740
- ]);
741
- }
742
- catch (e) {
743
- logger_1.default.error('rabbit: isConnected - false');
744
- return false;
745
- }
746
- logger_1.default.debug('rabbit: isConnected - true');
747
692
  return true;
748
693
  }
749
694
  async gracefulShutdown(signal) {
@@ -766,7 +711,6 @@ class RabbitMq {
766
711
  }
767
712
  async consumeFromRabbitOld(queue, callback, options) {
768
713
  const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
769
- debug('rabbit: consumeFromRabbitOld', { queue });
770
714
  RabbitMq.validateName('queue', queue);
771
715
  this.saveConsumerOld(queue, callback, options);
772
716
  const uniqueId = (0, node_crypto_1.randomUUID)();
@@ -858,12 +802,6 @@ class RabbitMq {
858
802
  // TODO: [QUORUM-PHASE-3] Delete all the function under this line (getNewChannelOld, getConnectionOld, assertQueueOld, setupQueueOld, saveConsumerOld)
859
803
  async getNewChannelOld({ name = (0, utils_1.rand)().toString(), onClose = null, options = {}, connection, }) {
860
804
  let localConnection;
861
- if (connection === this.oldPublishConnection) {
862
- debug('rabbit: getConnectionOld publish', { connection });
863
- }
864
- else if (connection === this.oldConsumeConnection) {
865
- debug('rabbit: getConnectionOld consume', { connection });
866
- }
867
805
  try {
868
806
  localConnection = await this.getConnectionOld(connection);
869
807
  }
@@ -874,12 +812,6 @@ class RabbitMq {
874
812
  if (!localConnection) {
875
813
  throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
876
814
  }
877
- if (connection === this.oldPublishConnection) {
878
- debug('rabbit: getNewChannelOld publish', { localConnection });
879
- }
880
- else if (connection === this.oldConsumeConnection) {
881
- debug('rabbit: getNewChannelOld consume', { localConnection });
882
- }
883
815
  const channel = localConnection?.createChannel({ ...options });
884
816
  (0, events_1.once)(channel, 'close').then((args) => {
885
817
  logger_1.default.error(`rabbit: channel ${name} closed`);
@@ -897,13 +829,7 @@ class RabbitMq {
897
829
  }
898
830
  async getConnectionOld(connection) {
899
831
  return new Promise(async (resolve, reject) => {
900
- const { connection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
901
- if (connection === this.oldPublishConnection) {
902
- debug('rabbit: getConnectionOld publish', { connectionLocal, creatingConnection, blockReconnect });
903
- }
904
- else if (connection === this.oldConsumeConnection) {
905
- debug('rabbit: getConnectionOld consume', { connectionLocal, creatingConnection, blockReconnect });
906
- }
832
+ const { amqpConnection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
907
833
  if (blockReconnect) {
908
834
  debug('rabbit: block reconnect');
909
835
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -941,13 +867,7 @@ class RabbitMq {
941
867
  const newConnection = await (0, amqp_connection_manager_1.connect)(defaultUrls, {
942
868
  findServers,
943
869
  });
944
- connection.connection = newConnection;
945
- if (connection === this.oldPublishConnection) {
946
- debug('rabbit: oldPublishConnection set');
947
- }
948
- else if (connection === this.oldConsumeConnection) {
949
- debug('rabbit: oldConsumeConnection set');
950
- }
870
+ connection.amqpConnection = newConnection;
951
871
  newConnection.on('error', (err) => {
952
872
  logger_1.default.error('rabbit: connection error', { err });
953
873
  if (!isResolved) {
@@ -1047,12 +967,6 @@ class RabbitMq {
1047
967
  return queue;
1048
968
  }
1049
969
  async assertChannelOld({ force = false, connection }) {
1050
- if (connection === this.oldPublishConnection) {
1051
- debug('rabbit: assertChannelOld publish', { force, promiseSetup: this.oldPublishChannelSetupPromise });
1052
- }
1053
- else if (connection === this.oldConsumeConnection) {
1054
- debug('rabbit: assertChannelOld consume', { force, promiseSetup: this.oldPublishChannelSetupPromise });
1055
- }
1056
970
  if (!this.oldPublishChannelSetupPromise) {
1057
971
  this.oldPublishChannelSetupPromise = new Promise(async (resolve, reject) => {
1058
972
  if (this.oldPublishChannel && !force) {
@@ -1060,17 +974,10 @@ class RabbitMq {
1060
974
  }
1061
975
  try {
1062
976
  const channel = await this.getNewChannelOld({ connection });
1063
- if (connection === this.oldPublishConnection) {
1064
- debug('rabbit: old new channel got publish', { force, channel });
1065
- }
1066
- else if (connection === this.oldConsumeConnection) {
1067
- debug('rabbit: old new channel got consume', { force, channel });
1068
- }
1069
977
  channel.on('error', (err) => {
1070
978
  logger_1.default.error('rabbit: channel error', { err });
1071
979
  });
1072
980
  if (this.oldPublishConnection === connection) {
1073
- debug('rabbit: a new channel assigned to the oldPublishChannel', { connection });
1074
981
  this.oldPublishChannel = channel;
1075
982
  }
1076
983
  resolve(channel);
@@ -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.16",
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,18 +409,13 @@ 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,
416
416
  blockReconnect,
417
417
  } = connection;
418
418
 
419
- if (connection === this.publishConnection) {
420
- debug('rabbit: getConnection publish', { connectionLocal, creatingConnection, blockReconnect });
421
- } else if (connection === this.consumeConnection) {
422
- debug('rabbit: getConnection consume', { connectionLocal, creatingConnection, blockReconnect });
423
- }
424
419
  if (blockReconnect) {
425
420
  debug('rabbit: block reconnect');
426
421
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -428,11 +423,6 @@ class RabbitMq implements IAfRabbitMq {
428
423
  return resolve();
429
424
  }
430
425
  if (connectionLocal !== null) {
431
- if (connection === this.publishConnection) {
432
- debug('rabbit: getConnection publish getConnection is not null', { connectionLocal });
433
- } else if (connection === this.consumeConnection) {
434
- debug('rabbit: getConnection consume getConnection is not null', { connectionLocal });
435
- }
436
426
  if (this.options?.disableReconnect || connectionLocal?.isConnected()) {
437
427
  debug('rabbit: connection - is connected');
438
428
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -467,12 +457,7 @@ class RabbitMq implements IAfRabbitMq {
467
457
  findServers,
468
458
  });
469
459
 
470
- connection.connection = newConnection;
471
- if (connection === this.publishConnection) {
472
- debug('rabbit: publishConnection set');
473
- } else if (connection === this.consumeConnection) {
474
- debug('rabbit: consumeConnection set');
475
- }
460
+ connection.amqpConnection = newConnection;
476
461
  newConnection.on('error', (err) => {
477
462
  logger.error('rabbit: connection error', { err });
478
463
  if (!isResolved) {
@@ -524,11 +509,6 @@ class RabbitMq implements IAfRabbitMq {
524
509
  logger.error(`rabbit: error on get connection for new channel ${name} `, { e });
525
510
  throw e;
526
511
  }
527
- if (connection === this.publishConnection) {
528
- debug('rabbit: getNewChannel publish', { localConnection });
529
- } else if (connection === this.consumeConnection) {
530
- debug('rabbit: getNewChannel consume', { localConnection });
531
- }
532
512
  const channel = localConnection?.createChannel({ ...options });
533
513
  once(channel, 'close').then((args) => {
534
514
  logger.error(`rabbit: channel ${name} closed`);
@@ -545,13 +525,6 @@ class RabbitMq implements IAfRabbitMq {
545
525
  }
546
526
 
547
527
  async assertChannel({ force = false, connection }: assertChannelOpts): Promise<ChannelWrapper> {
548
- if (connection === this.publishConnection) {
549
- debug('rabbit: assertChannel publish', { force, promiseSetup: this.oldPublishChannelSetupPromise });
550
- } else if (connection === this.consumeConnection) {
551
- debug('rabbit: assertChannel consume', { force, promiseSetup: this.oldPublishChannelSetupPromise });
552
- } else {
553
- debug('rabbit: assertChannel with undefined connection', { force, promiseSetup: this.oldPublishChannelSetupPromise, connection });
554
- }
555
528
  if (!this.publishChannelSetupPromise) {
556
529
  this.publishChannelSetupPromise = new Promise<ChannelWrapper>(async (resolve, reject) => {
557
530
  if (this.publishChannel && !force) {
@@ -599,7 +572,7 @@ class RabbitMq implements IAfRabbitMq {
599
572
  if (!channel) {
600
573
  throw new RabbitError('channel is not defined');
601
574
  }
602
- debug('rabbit: getting queue length', { queue, connected: this.connection?.isConnected() });
575
+ debug('rabbit: getting queue length', { queue, connected: this.oldPublishConnection.amqpConnection?.isConnected() });
603
576
  return channel?.checkQueue(queue);
604
577
  }
605
578
 
@@ -949,14 +922,13 @@ class RabbitMq implements IAfRabbitMq {
949
922
  }
950
923
 
951
924
  // TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
952
- async isConnected() : Promise<boolean> {
953
- // TODO: OLD IMPLEMENTATION
925
+ async isConnected(): Promise<boolean> {
954
926
  debug('rabbit: start old is connected');
955
927
  const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
956
928
  const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
957
929
  const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
958
930
  if (!oldIsConnected) {
959
- logger.error('rabbit: isConnected - false');
931
+ logger.error('rabbit: old isConnected - false');
960
932
  return false;
961
933
  }
962
934
  const oldChannel: any = await this.assertChannelOld({ connection: this.oldPublishConnection });
@@ -966,31 +938,10 @@ class RabbitMq implements IAfRabbitMq {
966
938
  ...this.oldConsumers.map((c: AfConsumer) => oldChannel.checkQueue(c.queue)),
967
939
  ]);
968
940
  } catch (e) {
969
- logger.error('rabbit: isConnected - false');
941
+ logger.error('rabbit: old isConnected - false');
970
942
  return false;
971
943
  }
972
944
  logger.debug('rabbit: old isConnected - true');
973
-
974
- // TODO: NEW IMPLEMENTATION
975
- debug('rabbit: start is connected');
976
- const consumeConnection = await this.getConnection(this.consumeConnection);
977
- const publishConnection = await this.getConnection(this.publishConnection);
978
- const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
979
- if (!isConnected) {
980
- logger.error('rabbit: isConnected - false');
981
- return false;
982
- }
983
- const channel: any = await this.assertChannel({ connection: this.publishConnection });
984
- try {
985
- await Promise.all([
986
- channel.waitForConnect(),
987
- ...this.consumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
988
- ]);
989
- } catch (e) {
990
- logger.error('rabbit: isConnected - false');
991
- return false;
992
- }
993
- logger.debug('rabbit: isConnected - true');
994
945
  return true;
995
946
  }
996
947
 
@@ -1014,7 +965,6 @@ class RabbitMq implements IAfRabbitMq {
1014
965
 
1015
966
  private async consumeFromRabbitOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
1016
967
  const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
1017
- debug('rabbit: consumeFromRabbitOld', { queue });
1018
968
  RabbitMq.validateName('queue', queue);
1019
969
  this.saveConsumerOld(queue, callback, options);
1020
970
  const uniqueId = randomUUID();
@@ -1122,11 +1072,6 @@ class RabbitMq implements IAfRabbitMq {
1122
1072
  name = rand().toString(), onClose = null, options = {}, connection,
1123
1073
  }: newChannelOpts) {
1124
1074
  let localConnection!: AmqpConnectionManager;
1125
- if (connection === this.oldPublishConnection) {
1126
- debug('rabbit: getConnectionOld publish', { connection });
1127
- } else if (connection === this.oldConsumeConnection) {
1128
- debug('rabbit: getConnectionOld consume', { connection });
1129
- }
1130
1075
  try {
1131
1076
  localConnection = await this.getConnectionOld(connection);
1132
1077
  } catch (e) {
@@ -1137,11 +1082,7 @@ class RabbitMq implements IAfRabbitMq {
1137
1082
  if (!localConnection) {
1138
1083
  throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
1139
1084
  }
1140
- if (connection === this.oldPublishConnection) {
1141
- debug('rabbit: getNewChannelOld publish', { localConnection });
1142
- } else if (connection === this.oldConsumeConnection) {
1143
- debug('rabbit: getNewChannelOld consume', { localConnection });
1144
- }
1085
+
1145
1086
  const channel = localConnection?.createChannel({ ...options });
1146
1087
  once(channel, 'close').then((args) => {
1147
1088
  logger.error(`rabbit: channel ${name} closed`);
@@ -1160,18 +1101,13 @@ class RabbitMq implements IAfRabbitMq {
1160
1101
  async getConnectionOld(connection: ConnectionData) {
1161
1102
  return new Promise<AmqpConnectionManager>(async (resolve, reject) => {
1162
1103
  const {
1163
- connection: connectionLocal,
1104
+ amqpConnection: connectionLocal,
1164
1105
  creatingConnection,
1165
1106
  connectionCreatedEventName,
1166
1107
  connectionFailedEventName,
1167
1108
  blockReconnect,
1168
1109
  } = connection;
1169
1110
 
1170
- if (connection === this.oldPublishConnection) {
1171
- debug('rabbit: getConnectionOld publish', { connectionLocal, creatingConnection, blockReconnect });
1172
- } else if (connection === this.oldConsumeConnection) {
1173
- debug('rabbit: getConnectionOld consume', { connectionLocal, creatingConnection, blockReconnect });
1174
- }
1175
1111
  if (blockReconnect) {
1176
1112
  debug('rabbit: block reconnect');
1177
1113
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -1214,12 +1150,7 @@ class RabbitMq implements IAfRabbitMq {
1214
1150
  findServers,
1215
1151
  });
1216
1152
 
1217
- connection.connection = newConnection;
1218
- if (connection === this.oldPublishConnection) {
1219
- debug('rabbit: oldPublishConnection set');
1220
- } else if (connection === this.oldConsumeConnection) {
1221
- debug('rabbit: oldConsumeConnection set');
1222
- }
1153
+ connection.amqpConnection = newConnection;
1223
1154
  newConnection.on('error', (err) => {
1224
1155
  logger.error('rabbit: connection error', { err });
1225
1156
  if (!isResolved) {
@@ -1327,11 +1258,6 @@ class RabbitMq implements IAfRabbitMq {
1327
1258
  }
1328
1259
 
1329
1260
  async assertChannelOld({ force = false, connection }: assertChannelOpts): Promise<ChannelWrapper> {
1330
- if (connection === this.oldPublishConnection) {
1331
- debug('rabbit: assertChannelOld publish', { force, promiseSetup: this.oldPublishChannelSetupPromise });
1332
- } else if (connection === this.oldConsumeConnection) {
1333
- debug('rabbit: assertChannelOld consume', { force, promiseSetup: this.oldPublishChannelSetupPromise });
1334
- }
1335
1261
  if (!this.oldPublishChannelSetupPromise) {
1336
1262
  this.oldPublishChannelSetupPromise = new Promise<ChannelWrapper>(async (resolve, reject) => {
1337
1263
  if (this.oldPublishChannel && !force) {
@@ -1340,16 +1266,10 @@ class RabbitMq implements IAfRabbitMq {
1340
1266
 
1341
1267
  try {
1342
1268
  const channel = await this.getNewChannelOld({ connection });
1343
- if (connection === this.oldPublishConnection) {
1344
- debug('rabbit: old new channel got publish', { force, channel });
1345
- } else if (connection === this.oldConsumeConnection) {
1346
- debug('rabbit: old new channel got consume', { force, channel });
1347
- }
1348
1269
  channel.on('error', (err) => {
1349
1270
  logger.error('rabbit: channel error', { err });
1350
1271
  });
1351
1272
  if (this.oldPublishConnection === connection) {
1352
- debug('rabbit: a new channel assigned to the oldPublishChannel', { connection });
1353
1273
  this.oldPublishChannel = channel;
1354
1274
  }
1355
1275
  resolve(channel);
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;