Retry Strategies
Message retry strategies allow you to specify how much of a delay should occur before retrying a message.
Delays between retries can be useful when messages fail handling due to race conditions, service unavailability, or concurrency reasons.
By default, @node-ts/bus uses a DefaultRetryStrategy that exponentially increases the delay between each retry attempt. Additionally, it will introduce a random variance of 10% for each delay to help unblock messages that are failing when processed at the same time.
Additional strategies can be implemented to suit your application.
Choosing a Retry Strategy
A retry strategy can be provided to the bus configuration on initialization by using .withRetryStrategy()
For example:
const bus = await Bus.configure()
.withRetryStrategy(DefaultRetryStrategy)
.initialize()Custom retry strategies
A custom retry strategy can be provided by implementing the RetryStrategy from @node-ts/bus-core.`
export type Milliseconds = number
/**
* Defines how a message retry strategy is to be implemented that calculates the delay between subsequent
* retries of a message.
*/
export interface RetryStrategy {
/**
* Calculate the delay between retrying a failed message
* @param currentAttempt How many attempts at handling the message have failed
* @returns The number of milliseconds to delay retrying a failed message attempt
*/
calculateRetryDelay (currentAttempt: number): Milliseconds
}
An example of a retry strategy is as follows
Last updated
Was this helpful?