@onlineapps/service-wrapper 2.1.95 → 2.1.97

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.
@@ -5,7 +5,10 @@
5
5
  "wrapper": {
6
6
  "mq": {
7
7
  "prefetch": 10,
8
- "enabled": true
8
+ "enabled": true,
9
+ "connectionRetries": 10,
10
+ "connectionRetryDelayMs": 2000,
11
+ "connectionRetryMaxDelayMs": 30000
9
12
  },
10
13
  "registry": {
11
14
  "enabled": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/service-wrapper",
3
- "version": "2.1.95",
3
+ "version": "2.1.97",
4
4
  "description": "Thin orchestration layer for microservices - delegates all infrastructure concerns to specialized connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -27,11 +27,11 @@
27
27
  "@onlineapps/conn-base-cache": "1.0.8",
28
28
  "@onlineapps/conn-base-monitoring": "1.0.9",
29
29
  "@onlineapps/conn-infra-error-handler": "1.0.8",
30
- "@onlineapps/conn-infra-mq": "1.1.66",
30
+ "@onlineapps/conn-infra-mq": "1.1.67",
31
31
  "@onlineapps/conn-orch-api-mapper": "1.0.26",
32
- "@onlineapps/conn-orch-cookbook": "2.0.28",
33
- "@onlineapps/conn-orch-orchestrator": "1.0.92",
34
- "@onlineapps/conn-orch-registry": "1.1.44",
32
+ "@onlineapps/conn-orch-cookbook": "2.0.29",
33
+ "@onlineapps/conn-orch-orchestrator": "1.0.93",
34
+ "@onlineapps/conn-orch-registry": "1.1.45",
35
35
  "@onlineapps/conn-orch-validator": "2.0.25",
36
36
  "@onlineapps/monitoring-core": "1.0.20",
37
37
  "@onlineapps/service-common": "1.0.15",
@@ -775,19 +775,39 @@ class ServiceWrapper {
775
775
  // Note: transport is created during connect(), so we need to register hooks after connect
776
776
  // We'll do this in a separate method called after connect
777
777
 
778
- try {
779
- await this.mqClient.connect();
780
- this.logger?.info('MQ connector initialized');
781
-
782
- } catch (error) {
783
- const message = `[MQConnector] Unable to connect to RabbitMQ at ${mqUrl}. ` +
784
- 'Verify that api_services_queuer is running and accessible. ' +
785
- `Original error: ${error.message || error}`;
786
- this.logger?.error(message, { error: error.message, code: error.code });
787
- const wrappedError = new Error(message);
788
- wrappedError.cause = error;
789
- throw wrappedError;
778
+ // Retry configuration from config or defaults
779
+ const maxRetries = this.config.wrapper?.mq?.connectionRetries ?? 10;
780
+ const initialDelayMs = this.config.wrapper?.mq?.connectionRetryDelayMs ?? 2000;
781
+ const maxDelayMs = this.config.wrapper?.mq?.connectionRetryMaxDelayMs ?? 30000;
782
+
783
+ let lastError = null;
784
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
785
+ try {
786
+ await this.mqClient.connect();
787
+ this.logger?.info('MQ connector initialized');
788
+ return; // Success - exit the function
789
+ } catch (error) {
790
+ lastError = error;
791
+ const delay = Math.min(initialDelayMs * Math.pow(2, attempt - 1), maxDelayMs);
792
+
793
+ if (attempt < maxRetries) {
794
+ this.logger?.warn(`[MQConnector] Connection attempt ${attempt}/${maxRetries} failed. Retrying in ${delay}ms...`, {
795
+ error: error.message,
796
+ nextRetryIn: delay
797
+ });
798
+ await new Promise(resolve => setTimeout(resolve, delay));
799
+ }
800
+ }
790
801
  }
802
+
803
+ // All retries exhausted
804
+ const message = `[MQConnector] Unable to connect to RabbitMQ at ${mqUrl} after ${maxRetries} attempts. ` +
805
+ 'Verify that api_services_queuer is running and accessible. ' +
806
+ `Original error: ${lastError?.message || lastError}`;
807
+ this.logger?.error(message, { error: lastError?.message, code: lastError?.code, attempts: maxRetries });
808
+ const wrappedError = new Error(message);
809
+ wrappedError.cause = lastError;
810
+ throw wrappedError;
791
811
 
792
812
  // NOTE: Business services (ServiceWrapper) do NOT create infrastructure queues
793
813
  // Infrastructure queues are created by infrastructure services (Monitoring Consumer, Gateway)