@autofleet/rabbit 3.4.0-beta.0 → 3.4.0-beta.10
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 +117 -42
- package/package.json +1 -1
- package/src/index.ts +116 -46
package/dist/index.js
CHANGED
|
@@ -209,15 +209,15 @@ class RabbitMq {
|
|
|
209
209
|
this.oldPublishConnection = {
|
|
210
210
|
connection: null,
|
|
211
211
|
creatingConnection: false,
|
|
212
|
-
connectionCreatedEventName: '
|
|
213
|
-
connectionFailedEventName: '
|
|
212
|
+
connectionCreatedEventName: 'oldPublishConnectionCreated',
|
|
213
|
+
connectionFailedEventName: 'oldPublishConnectionFailed',
|
|
214
214
|
blockReconnect: false,
|
|
215
215
|
};
|
|
216
216
|
this.oldConsumeConnection = {
|
|
217
217
|
connection: null,
|
|
218
218
|
creatingConnection: false,
|
|
219
|
-
connectionCreatedEventName: '
|
|
220
|
-
connectionFailedEventName: '
|
|
219
|
+
connectionCreatedEventName: 'oldConsumeConnectionCreated',
|
|
220
|
+
connectionFailedEventName: 'oldConsumeConnectionFailed',
|
|
221
221
|
blockReconnect: false,
|
|
222
222
|
};
|
|
223
223
|
this.oldCreatingConnection = false;
|
|
@@ -231,6 +231,12 @@ 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
|
+
}
|
|
234
240
|
if (blockReconnect) {
|
|
235
241
|
debug('rabbit: block reconnect');
|
|
236
242
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -269,6 +275,12 @@ class RabbitMq {
|
|
|
269
275
|
findServers,
|
|
270
276
|
});
|
|
271
277
|
connection.connection = newConnection;
|
|
278
|
+
if (connection === this.publishConnection) {
|
|
279
|
+
debug('rabbit: publishConnection set');
|
|
280
|
+
}
|
|
281
|
+
else if (connection === this.consumeConnection) {
|
|
282
|
+
debug('rabbit: consumeConnection set');
|
|
283
|
+
}
|
|
272
284
|
newConnection.on('error', (err) => {
|
|
273
285
|
logger_1.default.error('rabbit: connection error', { err });
|
|
274
286
|
if (!isResolved) {
|
|
@@ -316,7 +328,13 @@ class RabbitMq {
|
|
|
316
328
|
logger_1.default.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
317
329
|
throw e;
|
|
318
330
|
}
|
|
319
|
-
|
|
331
|
+
if (connection === this.publishConnection) {
|
|
332
|
+
debug('rabbit: getNewChannel publish', { localConnection });
|
|
333
|
+
}
|
|
334
|
+
else if (connection === this.consumeConnection) {
|
|
335
|
+
debug('rabbit: getNewChannel consume', { localConnection });
|
|
336
|
+
}
|
|
337
|
+
const channel = localConnection?.createChannel({ ...options });
|
|
320
338
|
(0, events_1.once)(channel, 'close').then((args) => {
|
|
321
339
|
logger_1.default.error(`rabbit: channel ${name} closed`);
|
|
322
340
|
onClose?.(args);
|
|
@@ -611,22 +629,24 @@ class RabbitMq {
|
|
|
611
629
|
]);
|
|
612
630
|
});
|
|
613
631
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
632
|
+
else {
|
|
633
|
+
// TODO: [QUORUM-PHASE-3] Delete the old implementation
|
|
634
|
+
await this.saveConsumerOld(queue, callback, options);
|
|
635
|
+
const channelOld = await this.getNewChannelOld({
|
|
636
|
+
name: `consume-exchange-${exchange}-queue-${queue}-old`,
|
|
637
|
+
connection: this.oldConsumeConnection,
|
|
638
|
+
});
|
|
639
|
+
await channelOld.addSetup(async (c) => {
|
|
640
|
+
const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
|
|
641
|
+
await c.assertQueue(queue);
|
|
642
|
+
this.oldExchanges[exchange] = assertExchange;
|
|
643
|
+
await c.prefetch(limit, false);
|
|
644
|
+
return Promise.all([
|
|
645
|
+
c.bindQueue(queue, exchange, ''),
|
|
646
|
+
this.consumeOld(queue, callback, options),
|
|
647
|
+
]);
|
|
648
|
+
});
|
|
649
|
+
}
|
|
630
650
|
}
|
|
631
651
|
// Used by the microservices to publish messages to the exchange
|
|
632
652
|
// TODO: [QUORUM-PHASE-2] Change the implementation to the new one
|
|
@@ -669,27 +689,47 @@ class RabbitMq {
|
|
|
669
689
|
}
|
|
670
690
|
// TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
|
|
671
691
|
async isConnected() {
|
|
672
|
-
debug('rabbit: start is connected');
|
|
673
|
-
const consumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
|
|
674
|
-
const publishConnection = await this.getConnectionOld(this.oldPublishConnection);
|
|
675
|
-
const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
|
|
676
|
-
if (!isConnected) {
|
|
677
|
-
logger_1.default.error('rabbit: isConnected - false');
|
|
678
|
-
return false;
|
|
679
|
-
}
|
|
680
|
-
const channel = await this.assertChannelOld({ connection: this.oldPublishConnection });
|
|
681
|
-
try {
|
|
682
|
-
await Promise.all([
|
|
683
|
-
channel.waitForConnect(),
|
|
684
|
-
...this.oldConsumers.map((c) => channel.checkQueue(c.queue)),
|
|
685
|
-
]);
|
|
686
|
-
}
|
|
687
|
-
catch (e) {
|
|
688
|
-
logger_1.default.error('rabbit: isConnected - false');
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
logger_1.default.debug('rabbit: isConnected - true');
|
|
692
|
+
debug('rabbit: start old is connected', { connection: this.oldPublishConnection.connectionCreatedEventName });
|
|
692
693
|
return true;
|
|
694
|
+
// debug('rabbit: start old is connected');
|
|
695
|
+
// const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
|
|
696
|
+
// const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
|
|
697
|
+
// const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
|
|
698
|
+
// if (!oldIsConnected) {
|
|
699
|
+
// logger.error('rabbit: isConnected - false');
|
|
700
|
+
// return false;
|
|
701
|
+
// }
|
|
702
|
+
// const oldChannel: any = await this.assertChannelOld({ connection: this.oldPublishConnection });
|
|
703
|
+
// try {
|
|
704
|
+
// await Promise.all([
|
|
705
|
+
// oldChannel.waitForConnect(),
|
|
706
|
+
// ...this.oldConsumers.map((c: AfConsumer) => oldChannel.checkQueue(c.queue)),
|
|
707
|
+
// ]);
|
|
708
|
+
// } catch (e) {
|
|
709
|
+
// logger.error('rabbit: isConnected - false');
|
|
710
|
+
// return false;
|
|
711
|
+
// }
|
|
712
|
+
// logger.debug('rabbit: old isConnected - true');
|
|
713
|
+
// debug('rabbit: start is connected');
|
|
714
|
+
// const consumeConnection = await this.getConnection(this.oldConsumeConnection);
|
|
715
|
+
// const publishConnection = await this.getConnection(this.oldPublishConnection);
|
|
716
|
+
// const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
|
|
717
|
+
// if (!isConnected) {
|
|
718
|
+
// logger.error('rabbit: isConnected - false');
|
|
719
|
+
// return false;
|
|
720
|
+
// }
|
|
721
|
+
// const channel: any = await this.assertChannel({ connection: this.oldPublishConnection });
|
|
722
|
+
// try {
|
|
723
|
+
// await Promise.all([
|
|
724
|
+
// channel.waitForConnect(),
|
|
725
|
+
// ...this.oldConsumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
726
|
+
// ]);
|
|
727
|
+
// } catch (e) {
|
|
728
|
+
// logger.error('rabbit: isConnected - false');
|
|
729
|
+
// return false;
|
|
730
|
+
// }
|
|
731
|
+
// logger.debug('rabbit: isConnected - true');
|
|
732
|
+
// return true;
|
|
693
733
|
}
|
|
694
734
|
async gracefulShutdown(signal) {
|
|
695
735
|
// TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
|
|
@@ -711,6 +751,7 @@ class RabbitMq {
|
|
|
711
751
|
}
|
|
712
752
|
async consumeFromRabbitOld(queue, callback, options) {
|
|
713
753
|
const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
|
|
754
|
+
debug('rabbit: consumeFromRabbitOld', { queue });
|
|
714
755
|
RabbitMq.validateName('queue', queue);
|
|
715
756
|
this.saveConsumerOld(queue, callback, options);
|
|
716
757
|
const uniqueId = (0, node_crypto_1.randomUUID)();
|
|
@@ -802,6 +843,12 @@ class RabbitMq {
|
|
|
802
843
|
// TODO: [QUORUM-PHASE-3] Delete all the function under this line (getNewChannelOld, getConnectionOld, assertQueueOld, setupQueueOld, saveConsumerOld)
|
|
803
844
|
async getNewChannelOld({ name = (0, utils_1.rand)().toString(), onClose = null, options = {}, connection, }) {
|
|
804
845
|
let localConnection;
|
|
846
|
+
if (connection === this.oldPublishConnection) {
|
|
847
|
+
debug('rabbit: getConnectionOld publish', { connection });
|
|
848
|
+
}
|
|
849
|
+
else if (connection === this.oldConsumeConnection) {
|
|
850
|
+
debug('rabbit: getConnectionOld consume', { connection });
|
|
851
|
+
}
|
|
805
852
|
try {
|
|
806
853
|
localConnection = await this.getConnectionOld(connection);
|
|
807
854
|
}
|
|
@@ -809,7 +856,11 @@ class RabbitMq {
|
|
|
809
856
|
logger_1.default.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
810
857
|
throw e;
|
|
811
858
|
}
|
|
812
|
-
|
|
859
|
+
if (!localConnection) {
|
|
860
|
+
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
861
|
+
}
|
|
862
|
+
debug('rabbit: getNewChannelOld', { localConnection });
|
|
863
|
+
const channel = localConnection?.createChannel({ ...options });
|
|
813
864
|
(0, events_1.once)(channel, 'close').then((args) => {
|
|
814
865
|
logger_1.default.error(`rabbit: channel ${name} closed`);
|
|
815
866
|
onClose?.(args);
|
|
@@ -827,6 +878,12 @@ class RabbitMq {
|
|
|
827
878
|
async getConnectionOld(connection) {
|
|
828
879
|
return new Promise(async (resolve, reject) => {
|
|
829
880
|
const { connection: connectionLocal, creatingConnection, connectionCreatedEventName, connectionFailedEventName, blockReconnect, } = connection;
|
|
881
|
+
if (connection === this.oldPublishConnection) {
|
|
882
|
+
debug('rabbit: getConnectionOld publish', { connectionLocal, creatingConnection, blockReconnect });
|
|
883
|
+
}
|
|
884
|
+
else if (connection === this.oldConsumeConnection) {
|
|
885
|
+
debug('rabbit: getConnectionOld consume', { connectionLocal, creatingConnection, blockReconnect });
|
|
886
|
+
}
|
|
830
887
|
if (blockReconnect) {
|
|
831
888
|
debug('rabbit: block reconnect');
|
|
832
889
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -865,6 +922,12 @@ class RabbitMq {
|
|
|
865
922
|
findServers,
|
|
866
923
|
});
|
|
867
924
|
connection.connection = newConnection;
|
|
925
|
+
if (connection === this.oldPublishConnection) {
|
|
926
|
+
debug('rabbit: oldPublishConnection set');
|
|
927
|
+
}
|
|
928
|
+
else if (connection === this.oldConsumeConnection) {
|
|
929
|
+
debug('rabbit: oldConsumeConnection set');
|
|
930
|
+
}
|
|
868
931
|
newConnection.on('error', (err) => {
|
|
869
932
|
logger_1.default.error('rabbit: connection error', { err });
|
|
870
933
|
if (!isResolved) {
|
|
@@ -964,6 +1027,12 @@ class RabbitMq {
|
|
|
964
1027
|
return queue;
|
|
965
1028
|
}
|
|
966
1029
|
async assertChannelOld({ force = false, connection }) {
|
|
1030
|
+
if (connection === this.oldPublishConnection) {
|
|
1031
|
+
debug('rabbit: assertChannelOld publish', { force, promiseSetup: this.oldPublishChannelSetupPromise });
|
|
1032
|
+
}
|
|
1033
|
+
else if (connection === this.oldConsumeConnection) {
|
|
1034
|
+
debug('rabbit: assertChannelOld consume', { force, promiseSetup: this.oldPublishChannelSetupPromise });
|
|
1035
|
+
}
|
|
967
1036
|
if (!this.oldPublishChannelSetupPromise) {
|
|
968
1037
|
this.oldPublishChannelSetupPromise = new Promise(async (resolve, reject) => {
|
|
969
1038
|
if (this.oldPublishChannel && !force) {
|
|
@@ -971,6 +1040,12 @@ class RabbitMq {
|
|
|
971
1040
|
}
|
|
972
1041
|
try {
|
|
973
1042
|
const channel = await this.getNewChannelOld({ connection });
|
|
1043
|
+
if (connection === this.oldPublishConnection) {
|
|
1044
|
+
debug('rabbit: old new channel got publish', { force, channel });
|
|
1045
|
+
}
|
|
1046
|
+
else if (connection === this.oldConsumeConnection) {
|
|
1047
|
+
debug('rabbit: old new channel got consume', { force, channel });
|
|
1048
|
+
}
|
|
974
1049
|
channel.on('error', (err) => {
|
|
975
1050
|
logger_1.default.error('rabbit: channel error', { err });
|
|
976
1051
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -258,15 +258,15 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
258
258
|
this.oldPublishConnection = {
|
|
259
259
|
connection: null,
|
|
260
260
|
creatingConnection: false,
|
|
261
|
-
connectionCreatedEventName: '
|
|
262
|
-
connectionFailedEventName: '
|
|
261
|
+
connectionCreatedEventName: 'oldPublishConnectionCreated',
|
|
262
|
+
connectionFailedEventName: 'oldPublishConnectionFailed',
|
|
263
263
|
blockReconnect: false,
|
|
264
264
|
};
|
|
265
265
|
this.oldConsumeConnection = {
|
|
266
266
|
connection: null,
|
|
267
267
|
creatingConnection: false,
|
|
268
|
-
connectionCreatedEventName: '
|
|
269
|
-
connectionFailedEventName: '
|
|
268
|
+
connectionCreatedEventName: 'oldConsumeConnectionCreated',
|
|
269
|
+
connectionFailedEventName: 'oldConsumeConnectionFailed',
|
|
270
270
|
blockReconnect: false,
|
|
271
271
|
};
|
|
272
272
|
this.oldCreatingConnection = false;
|
|
@@ -415,6 +415,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
415
415
|
connectionFailedEventName,
|
|
416
416
|
blockReconnect,
|
|
417
417
|
} = connection;
|
|
418
|
+
if (connection === this.publishConnection) {
|
|
419
|
+
debug('rabbit: getConnection publish', { connectionLocal, creatingConnection, blockReconnect });
|
|
420
|
+
} else if (connection === this.consumeConnection) {
|
|
421
|
+
debug('rabbit: getConnection consume', { connectionLocal, creatingConnection, blockReconnect });
|
|
422
|
+
}
|
|
418
423
|
if (blockReconnect) {
|
|
419
424
|
debug('rabbit: block reconnect');
|
|
420
425
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -457,6 +462,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
457
462
|
});
|
|
458
463
|
|
|
459
464
|
connection.connection = newConnection;
|
|
465
|
+
if (connection === this.publishConnection) {
|
|
466
|
+
debug('rabbit: publishConnection set');
|
|
467
|
+
} else if (connection === this.consumeConnection) {
|
|
468
|
+
debug('rabbit: consumeConnection set');
|
|
469
|
+
}
|
|
460
470
|
newConnection.on('error', (err) => {
|
|
461
471
|
logger.error('rabbit: connection error', { err });
|
|
462
472
|
if (!isResolved) {
|
|
@@ -508,7 +518,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
508
518
|
logger.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
509
519
|
throw e;
|
|
510
520
|
}
|
|
511
|
-
|
|
521
|
+
if (connection === this.publishConnection) {
|
|
522
|
+
debug('rabbit: getNewChannel publish', { localConnection });
|
|
523
|
+
} else if (connection === this.consumeConnection) {
|
|
524
|
+
debug('rabbit: getNewChannel consume', { localConnection });
|
|
525
|
+
}
|
|
526
|
+
const channel = localConnection?.createChannel({ ...options });
|
|
512
527
|
once(channel, 'close').then((args) => {
|
|
513
528
|
logger.error(`rabbit: channel ${name} closed`);
|
|
514
529
|
onClose?.(args);
|
|
@@ -848,28 +863,28 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
848
863
|
),
|
|
849
864
|
]);
|
|
850
865
|
});
|
|
866
|
+
} else {
|
|
867
|
+
// TODO: [QUORUM-PHASE-3] Delete the old implementation
|
|
868
|
+
await this.saveConsumerOld(queue, callback, options);
|
|
869
|
+
const channelOld: ChannelWrapper = await this.getNewChannelOld({
|
|
870
|
+
name: `consume-exchange-${exchange}-queue-${queue}-old`,
|
|
871
|
+
connection: this.oldConsumeConnection,
|
|
872
|
+
});
|
|
873
|
+
await channelOld.addSetup(async (c: ConfirmChannel) => {
|
|
874
|
+
const assertExchange = await assertExchangeFanout(c, exchange);
|
|
875
|
+
await c.assertQueue(queue);
|
|
876
|
+
this.oldExchanges[exchange] = assertExchange;
|
|
877
|
+
await c.prefetch(limit, false);
|
|
878
|
+
return Promise.all([
|
|
879
|
+
c.bindQueue(queue, exchange, ''),
|
|
880
|
+
this.consumeOld(
|
|
881
|
+
queue,
|
|
882
|
+
callback,
|
|
883
|
+
options,
|
|
884
|
+
),
|
|
885
|
+
]);
|
|
886
|
+
});
|
|
851
887
|
}
|
|
852
|
-
|
|
853
|
-
// TODO: [QUORUM-PHASE-3] Delete the old implementation
|
|
854
|
-
await this.saveConsumerOld(queue, callback, options);
|
|
855
|
-
const channelOld: ChannelWrapper = await this.getNewChannelOld({
|
|
856
|
-
name: `consume-exchange-${exchange}-queue-${queue}-old`,
|
|
857
|
-
connection: this.oldConsumeConnection,
|
|
858
|
-
});
|
|
859
|
-
await channelOld.addSetup(async (c: ConfirmChannel) => {
|
|
860
|
-
const assertExchange = await assertExchangeFanout(c, exchange);
|
|
861
|
-
await c.assertQueue(queue);
|
|
862
|
-
this.oldExchanges[exchange] = assertExchange;
|
|
863
|
-
await c.prefetch(limit, false);
|
|
864
|
-
return Promise.all([
|
|
865
|
-
c.bindQueue(queue, exchange, ''),
|
|
866
|
-
this.consumeOld(
|
|
867
|
-
queue,
|
|
868
|
-
callback,
|
|
869
|
-
options,
|
|
870
|
-
),
|
|
871
|
-
]);
|
|
872
|
-
});
|
|
873
888
|
}
|
|
874
889
|
|
|
875
890
|
// Used by the microservices to publish messages to the exchange
|
|
@@ -923,26 +938,48 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
923
938
|
|
|
924
939
|
// TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
|
|
925
940
|
async isConnected() : Promise<boolean> {
|
|
926
|
-
debug('rabbit: start is connected');
|
|
927
|
-
const consumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
|
|
928
|
-
const publishConnection = await this.getConnectionOld(this.oldPublishConnection);
|
|
929
|
-
const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
|
|
930
|
-
if (!isConnected) {
|
|
931
|
-
logger.error('rabbit: isConnected - false');
|
|
932
|
-
return false;
|
|
933
|
-
}
|
|
934
|
-
const channel: any = await this.assertChannelOld({ connection: this.oldPublishConnection });
|
|
935
|
-
try {
|
|
936
|
-
await Promise.all([
|
|
937
|
-
channel.waitForConnect(),
|
|
938
|
-
...this.oldConsumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
939
|
-
]);
|
|
940
|
-
} catch (e) {
|
|
941
|
-
logger.error('rabbit: isConnected - false');
|
|
942
|
-
return false;
|
|
943
|
-
}
|
|
944
|
-
logger.debug('rabbit: isConnected - true');
|
|
941
|
+
debug('rabbit: start old is connected', { connection: this.oldPublishConnection.connectionCreatedEventName });
|
|
945
942
|
return true;
|
|
943
|
+
// debug('rabbit: start old is connected');
|
|
944
|
+
// const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
|
|
945
|
+
// const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
|
|
946
|
+
// const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
|
|
947
|
+
// if (!oldIsConnected) {
|
|
948
|
+
// logger.error('rabbit: isConnected - false');
|
|
949
|
+
// return false;
|
|
950
|
+
// }
|
|
951
|
+
// const oldChannel: any = await this.assertChannelOld({ connection: this.oldPublishConnection });
|
|
952
|
+
// try {
|
|
953
|
+
// await Promise.all([
|
|
954
|
+
// oldChannel.waitForConnect(),
|
|
955
|
+
// ...this.oldConsumers.map((c: AfConsumer) => oldChannel.checkQueue(c.queue)),
|
|
956
|
+
// ]);
|
|
957
|
+
// } catch (e) {
|
|
958
|
+
// logger.error('rabbit: isConnected - false');
|
|
959
|
+
// return false;
|
|
960
|
+
// }
|
|
961
|
+
// logger.debug('rabbit: old isConnected - true');
|
|
962
|
+
|
|
963
|
+
// debug('rabbit: start is connected');
|
|
964
|
+
// const consumeConnection = await this.getConnection(this.oldConsumeConnection);
|
|
965
|
+
// const publishConnection = await this.getConnection(this.oldPublishConnection);
|
|
966
|
+
// const isConnected = consumeConnection.isConnected() && publishConnection.isConnected();
|
|
967
|
+
// if (!isConnected) {
|
|
968
|
+
// logger.error('rabbit: isConnected - false');
|
|
969
|
+
// return false;
|
|
970
|
+
// }
|
|
971
|
+
// const channel: any = await this.assertChannel({ connection: this.oldPublishConnection });
|
|
972
|
+
// try {
|
|
973
|
+
// await Promise.all([
|
|
974
|
+
// channel.waitForConnect(),
|
|
975
|
+
// ...this.oldConsumers.map((c: AfConsumer) => channel.checkQueue(c.queue)),
|
|
976
|
+
// ]);
|
|
977
|
+
// } catch (e) {
|
|
978
|
+
// logger.error('rabbit: isConnected - false');
|
|
979
|
+
// return false;
|
|
980
|
+
// }
|
|
981
|
+
// logger.debug('rabbit: isConnected - true');
|
|
982
|
+
// return true;
|
|
946
983
|
}
|
|
947
984
|
|
|
948
985
|
async gracefulShutdown(signal: string) : Promise<void> {
|
|
@@ -965,6 +1002,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
965
1002
|
|
|
966
1003
|
private async consumeFromRabbitOld(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
967
1004
|
const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
|
|
1005
|
+
debug('rabbit: consumeFromRabbitOld', { queue });
|
|
968
1006
|
RabbitMq.validateName('queue', queue);
|
|
969
1007
|
this.saveConsumerOld(queue, callback, options);
|
|
970
1008
|
const uniqueId = randomUUID();
|
|
@@ -1072,13 +1110,24 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1072
1110
|
name = rand().toString(), onClose = null, options = {}, connection,
|
|
1073
1111
|
}: newChannelOpts) {
|
|
1074
1112
|
let localConnection!: AmqpConnectionManager;
|
|
1113
|
+
if (connection === this.oldPublishConnection) {
|
|
1114
|
+
debug('rabbit: getConnectionOld publish', { connection });
|
|
1115
|
+
} else if (connection === this.oldConsumeConnection) {
|
|
1116
|
+
debug('rabbit: getConnectionOld consume', { connection });
|
|
1117
|
+
}
|
|
1075
1118
|
try {
|
|
1076
1119
|
localConnection = await this.getConnectionOld(connection);
|
|
1077
1120
|
} catch (e) {
|
|
1078
1121
|
logger.error(`rabbit: error on get connection for new channel ${name} `, { e });
|
|
1079
1122
|
throw e;
|
|
1080
1123
|
}
|
|
1081
|
-
|
|
1124
|
+
|
|
1125
|
+
if (!localConnection) {
|
|
1126
|
+
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
debug('rabbit: getNewChannelOld', { localConnection });
|
|
1130
|
+
const channel = localConnection?.createChannel({ ...options });
|
|
1082
1131
|
once(channel, 'close').then((args) => {
|
|
1083
1132
|
logger.error(`rabbit: channel ${name} closed`);
|
|
1084
1133
|
onClose?.(args);
|
|
@@ -1102,6 +1151,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1102
1151
|
connectionFailedEventName,
|
|
1103
1152
|
blockReconnect,
|
|
1104
1153
|
} = connection;
|
|
1154
|
+
|
|
1155
|
+
if (connection === this.oldPublishConnection) {
|
|
1156
|
+
debug('rabbit: getConnectionOld publish', { connectionLocal, creatingConnection, blockReconnect });
|
|
1157
|
+
} else if (connection === this.oldConsumeConnection) {
|
|
1158
|
+
debug('rabbit: getConnectionOld consume', { connectionLocal, creatingConnection, blockReconnect });
|
|
1159
|
+
}
|
|
1105
1160
|
if (blockReconnect) {
|
|
1106
1161
|
debug('rabbit: block reconnect');
|
|
1107
1162
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -1145,6 +1200,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1145
1200
|
});
|
|
1146
1201
|
|
|
1147
1202
|
connection.connection = newConnection;
|
|
1203
|
+
if (connection === this.oldPublishConnection) {
|
|
1204
|
+
debug('rabbit: oldPublishConnection set');
|
|
1205
|
+
} else if (connection === this.oldConsumeConnection) {
|
|
1206
|
+
debug('rabbit: oldConsumeConnection set');
|
|
1207
|
+
}
|
|
1148
1208
|
newConnection.on('error', (err) => {
|
|
1149
1209
|
logger.error('rabbit: connection error', { err });
|
|
1150
1210
|
if (!isResolved) {
|
|
@@ -1252,6 +1312,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1252
1312
|
}
|
|
1253
1313
|
|
|
1254
1314
|
async assertChannelOld({ force = false, connection }: assertChannelOpts): Promise<ChannelWrapper> {
|
|
1315
|
+
if (connection === this.oldPublishConnection) {
|
|
1316
|
+
debug('rabbit: assertChannelOld publish', { force, promiseSetup: this.oldPublishChannelSetupPromise });
|
|
1317
|
+
} else if (connection === this.oldConsumeConnection) {
|
|
1318
|
+
debug('rabbit: assertChannelOld consume', { force, promiseSetup: this.oldPublishChannelSetupPromise });
|
|
1319
|
+
}
|
|
1255
1320
|
if (!this.oldPublishChannelSetupPromise) {
|
|
1256
1321
|
this.oldPublishChannelSetupPromise = new Promise<ChannelWrapper>(async (resolve, reject) => {
|
|
1257
1322
|
if (this.oldPublishChannel && !force) {
|
|
@@ -1260,6 +1325,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1260
1325
|
|
|
1261
1326
|
try {
|
|
1262
1327
|
const channel = await this.getNewChannelOld({ connection });
|
|
1328
|
+
if (connection === this.oldPublishConnection) {
|
|
1329
|
+
debug('rabbit: old new channel got publish', { force, channel });
|
|
1330
|
+
} else if (connection === this.oldConsumeConnection) {
|
|
1331
|
+
debug('rabbit: old new channel got consume', { force, channel });
|
|
1332
|
+
}
|
|
1263
1333
|
channel.on('error', (err) => {
|
|
1264
1334
|
logger.error('rabbit: channel error', { err });
|
|
1265
1335
|
});
|