Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): add reconnection parameters to RecipientModuleConfig #1070

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/core/src/agent/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/agent/AgentModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/routing/RecipientApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions packages/core/src/modules/routing/RecipientModuleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down