@autofleet/rabbit 3.4.0-beta.16 → 3.4.0-beta.17
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 +2 -73
- package/package.json +1 -1
- package/src/index.ts +3 -61
package/dist/index.js
CHANGED
|
@@ -231,12 +231,6 @@ class RabbitMq {
|
|
|
231
231
|
async getConnection(connection) {
|
|
232
232
|
return new Promise(async (resolve, reject) => {
|
|
233
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
|
-
}
|
|
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
|
|
@@ -281,12 +269,6 @@ class RabbitMq {
|
|
|
281
269
|
findServers,
|
|
282
270
|
});
|
|
283
271
|
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
|
-
}
|
|
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) {
|
|
@@ -708,7 +675,7 @@ class RabbitMq {
|
|
|
708
675
|
const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
|
|
709
676
|
const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
|
|
710
677
|
if (!oldIsConnected) {
|
|
711
|
-
logger_1.default.error('rabbit: isConnected - false');
|
|
678
|
+
logger_1.default.error('rabbit: old isConnected - false');
|
|
712
679
|
return false;
|
|
713
680
|
}
|
|
714
681
|
const oldChannel = await this.assertChannelOld({ connection: this.oldPublishConnection });
|
|
@@ -719,7 +686,7 @@ class RabbitMq {
|
|
|
719
686
|
]);
|
|
720
687
|
}
|
|
721
688
|
catch (e) {
|
|
722
|
-
logger_1.default.error('rabbit: isConnected - false');
|
|
689
|
+
logger_1.default.error('rabbit: old isConnected - false');
|
|
723
690
|
return false;
|
|
724
691
|
}
|
|
725
692
|
logger_1.default.debug('rabbit: old isConnected - true');
|
|
@@ -766,7 +733,6 @@ class RabbitMq {
|
|
|
766
733
|
}
|
|
767
734
|
async consumeFromRabbitOld(queue, callback, options) {
|
|
768
735
|
const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
|
|
769
|
-
debug('rabbit: consumeFromRabbitOld', { queue });
|
|
770
736
|
RabbitMq.validateName('queue', queue);
|
|
771
737
|
this.saveConsumerOld(queue, callback, options);
|
|
772
738
|
const uniqueId = (0, node_crypto_1.randomUUID)();
|
|
@@ -858,12 +824,6 @@ class RabbitMq {
|
|
|
858
824
|
// TODO: [QUORUM-PHASE-3] Delete all the function under this line (getNewChannelOld, getConnectionOld, assertQueueOld, setupQueueOld, saveConsumerOld)
|
|
859
825
|
async getNewChannelOld({ name = (0, utils_1.rand)().toString(), onClose = null, options = {}, connection, }) {
|
|
860
826
|
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
827
|
try {
|
|
868
828
|
localConnection = await this.getConnectionOld(connection);
|
|
869
829
|
}
|
|
@@ -874,12 +834,6 @@ class RabbitMq {
|
|
|
874
834
|
if (!localConnection) {
|
|
875
835
|
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
876
836
|
}
|
|
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
837
|
const channel = localConnection?.createChannel({ ...options });
|
|
884
838
|
(0, events_1.once)(channel, 'close').then((args) => {
|
|
885
839
|
logger_1.default.error(`rabbit: channel ${name} closed`);
|
|
@@ -898,12 +852,6 @@ class RabbitMq {
|
|
|
898
852
|
async getConnectionOld(connection) {
|
|
899
853
|
return new Promise(async (resolve, reject) => {
|
|
900
854
|
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
|
-
}
|
|
907
855
|
if (blockReconnect) {
|
|
908
856
|
debug('rabbit: block reconnect');
|
|
909
857
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -942,12 +890,6 @@ class RabbitMq {
|
|
|
942
890
|
findServers,
|
|
943
891
|
});
|
|
944
892
|
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
|
-
}
|
|
951
893
|
newConnection.on('error', (err) => {
|
|
952
894
|
logger_1.default.error('rabbit: connection error', { err });
|
|
953
895
|
if (!isResolved) {
|
|
@@ -1047,12 +989,6 @@ class RabbitMq {
|
|
|
1047
989
|
return queue;
|
|
1048
990
|
}
|
|
1049
991
|
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
992
|
if (!this.oldPublishChannelSetupPromise) {
|
|
1057
993
|
this.oldPublishChannelSetupPromise = new Promise(async (resolve, reject) => {
|
|
1058
994
|
if (this.oldPublishChannel && !force) {
|
|
@@ -1060,17 +996,10 @@ class RabbitMq {
|
|
|
1060
996
|
}
|
|
1061
997
|
try {
|
|
1062
998
|
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
999
|
channel.on('error', (err) => {
|
|
1070
1000
|
logger_1.default.error('rabbit: channel error', { err });
|
|
1071
1001
|
});
|
|
1072
1002
|
if (this.oldPublishConnection === connection) {
|
|
1073
|
-
debug('rabbit: a new channel assigned to the oldPublishChannel', { connection });
|
|
1074
1003
|
this.oldPublishChannel = channel;
|
|
1075
1004
|
}
|
|
1076
1005
|
resolve(channel);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -416,11 +416,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
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
|
|
@@ -468,11 +458,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
468
458
|
});
|
|
469
459
|
|
|
470
460
|
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
|
-
}
|
|
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) {
|
|
@@ -956,7 +929,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
956
929
|
const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
|
|
957
930
|
const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
|
|
958
931
|
if (!oldIsConnected) {
|
|
959
|
-
logger.error('rabbit: isConnected - false');
|
|
932
|
+
logger.error('rabbit: old isConnected - false');
|
|
960
933
|
return false;
|
|
961
934
|
}
|
|
962
935
|
const oldChannel: any = await this.assertChannelOld({ connection: this.oldPublishConnection });
|
|
@@ -966,7 +939,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
966
939
|
...this.oldConsumers.map((c: AfConsumer) => oldChannel.checkQueue(c.queue)),
|
|
967
940
|
]);
|
|
968
941
|
} catch (e) {
|
|
969
|
-
logger.error('rabbit: isConnected - false');
|
|
942
|
+
logger.error('rabbit: old isConnected - false');
|
|
970
943
|
return false;
|
|
971
944
|
}
|
|
972
945
|
logger.debug('rabbit: old isConnected - true');
|
|
@@ -1014,7 +987,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1014
987
|
|
|
1015
988
|
private async consumeFromRabbitOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
1016
989
|
const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
|
|
1017
|
-
debug('rabbit: consumeFromRabbitOld', { queue });
|
|
1018
990
|
RabbitMq.validateName('queue', queue);
|
|
1019
991
|
this.saveConsumerOld(queue, callback, options);
|
|
1020
992
|
const uniqueId = randomUUID();
|
|
@@ -1122,11 +1094,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1122
1094
|
name = rand().toString(), onClose = null, options = {}, connection,
|
|
1123
1095
|
}: newChannelOpts) {
|
|
1124
1096
|
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
1097
|
try {
|
|
1131
1098
|
localConnection = await this.getConnectionOld(connection);
|
|
1132
1099
|
} catch (e) {
|
|
@@ -1137,11 +1104,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1137
1104
|
if (!localConnection) {
|
|
1138
1105
|
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
1139
1106
|
}
|
|
1140
|
-
|
|
1141
|
-
debug('rabbit: getNewChannelOld publish', { localConnection });
|
|
1142
|
-
} else if (connection === this.oldConsumeConnection) {
|
|
1143
|
-
debug('rabbit: getNewChannelOld consume', { localConnection });
|
|
1144
|
-
}
|
|
1107
|
+
|
|
1145
1108
|
const channel = localConnection?.createChannel({ ...options });
|
|
1146
1109
|
once(channel, 'close').then((args) => {
|
|
1147
1110
|
logger.error(`rabbit: channel ${name} closed`);
|
|
@@ -1167,11 +1130,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1167
1130
|
blockReconnect,
|
|
1168
1131
|
} = connection;
|
|
1169
1132
|
|
|
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
1133
|
if (blockReconnect) {
|
|
1176
1134
|
debug('rabbit: block reconnect');
|
|
1177
1135
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -1215,11 +1173,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1215
1173
|
});
|
|
1216
1174
|
|
|
1217
1175
|
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
|
-
}
|
|
1223
1176
|
newConnection.on('error', (err) => {
|
|
1224
1177
|
logger.error('rabbit: connection error', { err });
|
|
1225
1178
|
if (!isResolved) {
|
|
@@ -1327,11 +1280,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1327
1280
|
}
|
|
1328
1281
|
|
|
1329
1282
|
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
1283
|
if (!this.oldPublishChannelSetupPromise) {
|
|
1336
1284
|
this.oldPublishChannelSetupPromise = new Promise<ChannelWrapper>(async (resolve, reject) => {
|
|
1337
1285
|
if (this.oldPublishChannel && !force) {
|
|
@@ -1340,16 +1288,10 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1340
1288
|
|
|
1341
1289
|
try {
|
|
1342
1290
|
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
1291
|
channel.on('error', (err) => {
|
|
1349
1292
|
logger.error('rabbit: channel error', { err });
|
|
1350
1293
|
});
|
|
1351
1294
|
if (this.oldPublishConnection === connection) {
|
|
1352
|
-
debug('rabbit: a new channel assigned to the oldPublishChannel', { connection });
|
|
1353
1295
|
this.oldPublishChannel = channel;
|
|
1354
1296
|
}
|
|
1355
1297
|
resolve(channel);
|