@autofleet/rabbit 3.4.0-beta.11 → 3.4.0-beta.13
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 +26 -23
- package/package.json +1 -1
- package/src/index.ts +30 -27
package/dist/index.js
CHANGED
|
@@ -486,10 +486,10 @@ class RabbitMq {
|
|
|
486
486
|
// Used by the microservices to consume messages from the queue
|
|
487
487
|
async consume(queue, callback, options) {
|
|
488
488
|
// TODO: [QUORUM-PHASE-3] Use only the implementation of consumeNew and delete consumeNew and consumeOld
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
489
|
+
if (options?.isQuorumQueue !== false) {
|
|
490
|
+
await this.assertVHost();
|
|
491
|
+
await this.consumeNew(queue, callback, options);
|
|
492
|
+
}
|
|
493
493
|
await this.consumeOld(queue, callback, options);
|
|
494
494
|
}
|
|
495
495
|
// TODO: [QUORUM-PHASE-3] Delete consumeNew we do not use it anymore
|
|
@@ -629,24 +629,22 @@ class RabbitMq {
|
|
|
629
629
|
]);
|
|
630
630
|
});
|
|
631
631
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
await
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
});
|
|
649
|
-
}
|
|
632
|
+
// TODO: [QUORUM-PHASE-3] Delete the old implementation
|
|
633
|
+
await this.saveConsumerOld(queue, callback, options);
|
|
634
|
+
const channelOld = await this.getNewChannelOld({
|
|
635
|
+
name: `consume-exchange-${exchange}-queue-${queue}-old`,
|
|
636
|
+
connection: this.oldConsumeConnection,
|
|
637
|
+
});
|
|
638
|
+
await channelOld.addSetup(async (c) => {
|
|
639
|
+
const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
|
|
640
|
+
await c.assertQueue(queue);
|
|
641
|
+
this.oldExchanges[exchange] = assertExchange;
|
|
642
|
+
await c.prefetch(limit, false);
|
|
643
|
+
return Promise.all([
|
|
644
|
+
c.bindQueue(queue, exchange, ''),
|
|
645
|
+
this.consumeOld(queue, callback, options),
|
|
646
|
+
]);
|
|
647
|
+
});
|
|
650
648
|
}
|
|
651
649
|
// Used by the microservices to publish messages to the exchange
|
|
652
650
|
// TODO: [QUORUM-PHASE-2] Change the implementation to the new one
|
|
@@ -859,7 +857,12 @@ class RabbitMq {
|
|
|
859
857
|
if (!localConnection) {
|
|
860
858
|
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
861
859
|
}
|
|
862
|
-
|
|
860
|
+
if (connection === this.oldPublishConnection) {
|
|
861
|
+
debug('rabbit: getNewChannelOld publish', { localConnection });
|
|
862
|
+
}
|
|
863
|
+
else if (connection === this.oldConsumeConnection) {
|
|
864
|
+
debug('rabbit: getNewChannelOld consume', { localConnection });
|
|
865
|
+
}
|
|
863
866
|
const channel = localConnection?.createChannel({ ...options });
|
|
864
867
|
(0, events_1.once)(channel, 'close').then((args) => {
|
|
865
868
|
logger_1.default.error(`rabbit: channel ${name} closed`);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -415,6 +415,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
415
415
|
connectionFailedEventName,
|
|
416
416
|
blockReconnect,
|
|
417
417
|
} = connection;
|
|
418
|
+
|
|
418
419
|
if (connection === this.publishConnection) {
|
|
419
420
|
debug('rabbit: getConnection publish', { connectionLocal, creatingConnection, blockReconnect });
|
|
420
421
|
} else if (connection === this.consumeConnection) {
|
|
@@ -692,10 +693,10 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
692
693
|
// Used by the microservices to consume messages from the queue
|
|
693
694
|
async consume(queue: string, callback: CallbackFunction, options?: ConsumeOptions): Promise<any> {
|
|
694
695
|
// TODO: [QUORUM-PHASE-3] Use only the implementation of consumeNew and delete consumeNew and consumeOld
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
696
|
+
if (options?.isQuorumQueue !== false) {
|
|
697
|
+
await this.assertVHost();
|
|
698
|
+
await this.consumeNew(queue, callback, options);
|
|
699
|
+
}
|
|
699
700
|
|
|
700
701
|
await this.consumeOld(queue, callback, options);
|
|
701
702
|
}
|
|
@@ -863,28 +864,27 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
863
864
|
),
|
|
864
865
|
]);
|
|
865
866
|
});
|
|
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
|
-
});
|
|
887
867
|
}
|
|
868
|
+
// TODO: [QUORUM-PHASE-3] Delete the old implementation
|
|
869
|
+
await this.saveConsumerOld(queue, callback, options);
|
|
870
|
+
const channelOld: ChannelWrapper = await this.getNewChannelOld({
|
|
871
|
+
name: `consume-exchange-${exchange}-queue-${queue}-old`,
|
|
872
|
+
connection: this.oldConsumeConnection,
|
|
873
|
+
});
|
|
874
|
+
await channelOld.addSetup(async (c: ConfirmChannel) => {
|
|
875
|
+
const assertExchange = await assertExchangeFanout(c, exchange);
|
|
876
|
+
await c.assertQueue(queue);
|
|
877
|
+
this.oldExchanges[exchange] = assertExchange;
|
|
878
|
+
await c.prefetch(limit, false);
|
|
879
|
+
return Promise.all([
|
|
880
|
+
c.bindQueue(queue, exchange, ''),
|
|
881
|
+
this.consumeOld(
|
|
882
|
+
queue,
|
|
883
|
+
callback,
|
|
884
|
+
options,
|
|
885
|
+
),
|
|
886
|
+
]);
|
|
887
|
+
});
|
|
888
888
|
}
|
|
889
889
|
|
|
890
890
|
// Used by the microservices to publish messages to the exchange
|
|
@@ -1125,8 +1125,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
1125
1125
|
if (!localConnection) {
|
|
1126
1126
|
throw new Error(`rabbit: couldnt get connection for new channel ${name}`);
|
|
1127
1127
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1128
|
+
if (connection === this.oldPublishConnection) {
|
|
1129
|
+
debug('rabbit: getNewChannelOld publish', { localConnection });
|
|
1130
|
+
} else if (connection === this.oldConsumeConnection) {
|
|
1131
|
+
debug('rabbit: getNewChannelOld consume', { localConnection });
|
|
1132
|
+
}
|
|
1130
1133
|
const channel = localConnection?.createChannel({ ...options });
|
|
1131
1134
|
once(channel, 'close').then((args) => {
|
|
1132
1135
|
logger.error(`rabbit: channel ${name} closed`);
|