@autofleet/rabbit 3.4.0-beta.6 → 3.4.0-beta.8

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.
Files changed (3) hide show
  1. package/dist/index.js +38 -16
  2. package/package.json +1 -1
  3. package/src/index.ts +41 -21
package/dist/index.js CHANGED
@@ -617,22 +617,24 @@ class RabbitMq {
617
617
  ]);
618
618
  });
619
619
  }
620
- // TODO: [QUORUM-PHASE-3] Delete the old implementation
621
- await this.saveConsumerOld(queue, callback, options);
622
- const channelOld = await this.getNewChannelOld({
623
- name: `consume-exchange-${exchange}-queue-${queue}-old`,
624
- connection: this.oldConsumeConnection,
625
- });
626
- await channelOld.addSetup(async (c) => {
627
- const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
628
- await c.assertQueue(queue);
629
- this.oldExchanges[exchange] = assertExchange;
630
- await c.prefetch(limit, false);
631
- return Promise.all([
632
- c.bindQueue(queue, exchange, ''),
633
- this.consumeOld(queue, callback, options),
634
- ]);
635
- });
620
+ else {
621
+ // TODO: [QUORUM-PHASE-3] Delete the old implementation
622
+ await this.saveConsumerOld(queue, callback, options);
623
+ const channelOld = await this.getNewChannelOld({
624
+ name: `consume-exchange-${exchange}-queue-${queue}-old`,
625
+ connection: this.oldConsumeConnection,
626
+ });
627
+ await channelOld.addSetup(async (c) => {
628
+ const assertExchange = await (0, utils_1.assertExchangeFanout)(c, exchange);
629
+ await c.assertQueue(queue);
630
+ this.oldExchanges[exchange] = assertExchange;
631
+ await c.prefetch(limit, false);
632
+ return Promise.all([
633
+ c.bindQueue(queue, exchange, ''),
634
+ this.consumeOld(queue, callback, options),
635
+ ]);
636
+ });
637
+ }
636
638
  }
637
639
  // Used by the microservices to publish messages to the exchange
638
640
  // TODO: [QUORUM-PHASE-2] Change the implementation to the new one
@@ -675,6 +677,26 @@ class RabbitMq {
675
677
  }
676
678
  // TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
677
679
  async isConnected() {
680
+ debug('rabbit: start old is connected');
681
+ const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
682
+ const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
683
+ const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
684
+ if (!oldIsConnected) {
685
+ logger_1.default.error('rabbit: isConnected - false');
686
+ return false;
687
+ }
688
+ const oldChannel = await this.assertChannelOld({ connection: this.oldPublishConnection });
689
+ try {
690
+ await Promise.all([
691
+ oldChannel.waitForConnect(),
692
+ ...this.oldConsumers.map((c) => oldChannel.checkQueue(c.queue)),
693
+ ]);
694
+ }
695
+ catch (e) {
696
+ logger_1.default.error('rabbit: isConnected - false');
697
+ return false;
698
+ }
699
+ logger_1.default.debug('rabbit: old isConnected - true');
678
700
  debug('rabbit: start is connected');
679
701
  const consumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
680
702
  const publishConnection = await this.getConnectionOld(this.oldPublishConnection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.4.0-beta.6",
3
+ "version": "3.4.0-beta.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
package/src/index.ts CHANGED
@@ -853,28 +853,28 @@ class RabbitMq implements IAfRabbitMq {
853
853
  ),
854
854
  ]);
855
855
  });
856
+ } else {
857
+ // TODO: [QUORUM-PHASE-3] Delete the old implementation
858
+ await this.saveConsumerOld(queue, callback, options);
859
+ const channelOld: ChannelWrapper = await this.getNewChannelOld({
860
+ name: `consume-exchange-${exchange}-queue-${queue}-old`,
861
+ connection: this.oldConsumeConnection,
862
+ });
863
+ await channelOld.addSetup(async (c: ConfirmChannel) => {
864
+ const assertExchange = await assertExchangeFanout(c, exchange);
865
+ await c.assertQueue(queue);
866
+ this.oldExchanges[exchange] = assertExchange;
867
+ await c.prefetch(limit, false);
868
+ return Promise.all([
869
+ c.bindQueue(queue, exchange, ''),
870
+ this.consumeOld(
871
+ queue,
872
+ callback,
873
+ options,
874
+ ),
875
+ ]);
876
+ });
856
877
  }
857
-
858
- // TODO: [QUORUM-PHASE-3] Delete the old implementation
859
- await this.saveConsumerOld(queue, callback, options);
860
- const channelOld: ChannelWrapper = await this.getNewChannelOld({
861
- name: `consume-exchange-${exchange}-queue-${queue}-old`,
862
- connection: this.oldConsumeConnection,
863
- });
864
- await channelOld.addSetup(async (c: ConfirmChannel) => {
865
- const assertExchange = await assertExchangeFanout(c, exchange);
866
- await c.assertQueue(queue);
867
- this.oldExchanges[exchange] = assertExchange;
868
- await c.prefetch(limit, false);
869
- return Promise.all([
870
- c.bindQueue(queue, exchange, ''),
871
- this.consumeOld(
872
- queue,
873
- callback,
874
- options,
875
- ),
876
- ]);
877
- });
878
878
  }
879
879
 
880
880
  // Used by the microservices to publish messages to the exchange
@@ -928,6 +928,26 @@ class RabbitMq implements IAfRabbitMq {
928
928
 
929
929
  // TODO: [QUORUM-PHASE-2] After changing the publish from old to new change from the old to the new implementation
930
930
  async isConnected() : Promise<boolean> {
931
+ debug('rabbit: start old is connected');
932
+ const oldConsumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
933
+ const oldPublishConnection = await this.getConnectionOld(this.oldPublishConnection);
934
+ const oldIsConnected = oldConsumeConnection.isConnected() && oldPublishConnection.isConnected();
935
+ if (!oldIsConnected) {
936
+ logger.error('rabbit: isConnected - false');
937
+ return false;
938
+ }
939
+ const oldChannel: any = await this.assertChannelOld({ connection: this.oldPublishConnection });
940
+ try {
941
+ await Promise.all([
942
+ oldChannel.waitForConnect(),
943
+ ...this.oldConsumers.map((c: AfConsumer) => oldChannel.checkQueue(c.queue)),
944
+ ]);
945
+ } catch (e) {
946
+ logger.error('rabbit: isConnected - false');
947
+ return false;
948
+ }
949
+ logger.debug('rabbit: old isConnected - true');
950
+
931
951
  debug('rabbit: start is connected');
932
952
  const consumeConnection = await this.getConnectionOld(this.oldConsumeConnection);
933
953
  const publishConnection = await this.getConnectionOld(this.oldPublishConnection);