@onlineapps/service-wrapper 2.1.94 → 2.1.96
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/config/runtime-defaults.json +4 -1
- package/package.json +1 -1
- package/src/ServiceWrapper.js +34 -20
package/package.json
CHANGED
package/src/ServiceWrapper.js
CHANGED
|
@@ -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
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
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)
|
|
@@ -837,13 +857,7 @@ class ServiceWrapper {
|
|
|
837
857
|
);
|
|
838
858
|
}
|
|
839
859
|
|
|
840
|
-
//
|
|
841
|
-
if (!this.logger) {
|
|
842
|
-
throw new Error(
|
|
843
|
-
`[ServiceWrapper] Missing required dependency - logger is not initialized.`
|
|
844
|
-
);
|
|
845
|
-
}
|
|
846
|
-
|
|
860
|
+
// Logger may not be initialized yet at this point - RegistryClient handles null gracefully
|
|
847
861
|
this.registryClient = new RegistryConnector.ServiceRegistryClient({
|
|
848
862
|
amqpUrl: mqUrl,
|
|
849
863
|
serviceName: serviceName,
|
|
@@ -851,7 +865,7 @@ class ServiceWrapper {
|
|
|
851
865
|
specificationEndpoint: specificationEndpoint,
|
|
852
866
|
registryQueue: 'registry.register', // Use correct queue name
|
|
853
867
|
registryUrl: registryUrl,
|
|
854
|
-
logger: this.logger,
|
|
868
|
+
logger: this.logger || console, // Use console as fallback if logger not yet initialized
|
|
855
869
|
validationProof: this.validationProof // Inject validation proof
|
|
856
870
|
});
|
|
857
871
|
|