diff --git a/packages/core/src/agent/AgentConfig.ts b/packages/core/src/agent/AgentConfig.ts index 10d56e61da..3b6297341b 100644 --- a/packages/core/src/agent/AgentConfig.ts +++ b/packages/core/src/agent/AgentConfig.ts @@ -104,11 +104,16 @@ export class AgentConfig { public get maximumMessagePickup() { return this.initConfig.maximumMessagePickup ?? 10 } - + /** + * @deprecated use baseMediatorReconnectionIntervalMs from the `RecipientModuleConfig` class + */ public get baseMediatorReconnectionIntervalMs() { return this.initConfig.baseMediatorReconnectionIntervalMs ?? 100 } + /** + * @deprecated use maximumMediatorReconnectionIntervalMs from the `RecipientModuleConfig` class + */ public get maximumMediatorReconnectionIntervalMs() { return this.initConfig.maximumMediatorReconnectionIntervalMs ?? Number.POSITIVE_INFINITY } diff --git a/packages/core/src/agent/AgentModules.ts b/packages/core/src/agent/AgentModules.ts index 05055ebf97..6bf2de802e 100644 --- a/packages/core/src/agent/AgentModules.ts +++ b/packages/core/src/agent/AgentModules.ts @@ -113,6 +113,8 @@ function getDefaultAgentModules(agentConfig: AgentConfig) { maximumMessagePickup: agentConfig.maximumMessagePickup, mediatorInvitationUrl: agentConfig.mediatorConnectionsInvite, mediatorPickupStrategy: agentConfig.mediatorPickupStrategy, + baseMediatorReconnectionIntervalMs: agentConfig.baseMediatorReconnectionIntervalMs, + maximumMediatorReconnectionIntervalMs: agentConfig.maximumMediatorReconnectionIntervalMs, mediatorPollingInterval: agentConfig.mediatorPollingInterval, }), basicMessages: () => new BasicMessagesModule(), diff --git a/packages/core/src/modules/routing/RecipientApi.ts b/packages/core/src/modules/routing/RecipientApi.ts index c761826211..dc99a1b46c 100644 --- a/packages/core/src/modules/routing/RecipientApi.ts +++ b/packages/core/src/modules/routing/RecipientApi.ts @@ -151,7 +151,7 @@ export class RecipientApi { } private async openWebSocketAndPickUp(mediator: MediationRecord, pickupStrategy: MediatorPickupStrategy) { - const { baseMediatorReconnectionIntervalMs, maximumMediatorReconnectionIntervalMs } = this.agentContext.config + const { baseMediatorReconnectionIntervalMs, maximumMediatorReconnectionIntervalMs } = this.config let interval = baseMediatorReconnectionIntervalMs const stopConditions$ = merge(this.stop$, this.stopMessagePickup$).pipe() diff --git a/packages/core/src/modules/routing/RecipientModuleConfig.ts b/packages/core/src/modules/routing/RecipientModuleConfig.ts index d8679c4fad..4463289936 100644 --- a/packages/core/src/modules/routing/RecipientModuleConfig.ts +++ b/packages/core/src/modules/routing/RecipientModuleConfig.ts @@ -36,6 +36,29 @@ export interface RecipientModuleConfigOptions { */ maximumMessagePickup?: number + /** + * Initial interval in milliseconds between reconnection attempts when losing connection with the mediator. This value is doubled after + * each retry, resulting in an exponential backoff strategy. + * + * For instance, if maximumMediatorReconnectionIntervalMs is b, the agent will attempt to reconnect after b, 2*b, 4*b, 8*b, 16*b, ... ms. + * + * This is only applicable when pickup protocol v2 or implicit pickup is used. + * + * @default 100 + */ + baseMediatorReconnectionIntervalMs?: number + + /** + * Maximum interval in milliseconds between reconnection attempts when losing connection with the mediator. + * + * For instance, if maximumMediatorReconnectionIntervalMs is set to 1000 and maximumMediatorReconnectionIntervalMs is set to 10000, + * the agent will attempt to reconnect after 1000, 2000, 4000, 8000, 10000, ..., 10000 ms. + * + * This is only applicable when pickup protocol v2 or implicit pickup is used. + * @default Number.POSITIVE_INFINITY + */ + maximumMediatorReconnectionIntervalMs?: number + /** * Invitation url for connection to a mediator. If provided, a connection to the mediator will be made, and the mediator will be set as default. * This is meant as the simplest form of connecting to a mediator, if more control is desired the api should be used. @@ -67,6 +90,16 @@ export class RecipientModuleConfig { return this.options.maximumMessagePickup ?? 10 } + /** See {@link RecipientModuleConfigOptions.baseMediatorReconnectionIntervalMs} */ + public get baseMediatorReconnectionIntervalMs() { + return this.options.baseMediatorReconnectionIntervalMs ?? 100 + } + + /** See {@link RecipientModuleConfigOptions.maximumMediatorReconnectionIntervalMs} */ + public get maximumMediatorReconnectionIntervalMs() { + return this.options.maximumMediatorReconnectionIntervalMs ?? Number.POSITIVE_INFINITY + } + /** See {@link RecipientModuleConfigOptions.mediatorInvitationUrl} */ public get mediatorInvitationUrl() { return this.options.mediatorInvitationUrl