Retryer Middleware
The Retryer Middleware is built-in middleware that gives you capability to retry the handling of an intent.
How to use it
As for any Middleware, you can use it by adding it to the bus
instance.
const commandBus = createCommandBus<CommandHandlerRegistry>();commandBus.useRetryerMiddleware({ maxAttempts: 5; waitingAlgorithm: 'exponential', multiplier: 1.5; jitter: 0.5;});
Remember built-in middlewares are intent aware, therefore you can customize the behavior per intent using the key
intents
.
Explanation
The Retryer middleware is going to catch the execution and re-run the following middleware until the maxAttempts
is reached.
Between each attempt, the middleware is going to wait for a certain amount of time.
The waitingAlgorithm
can be exponential
, fibonacci
, or none
.
jitter
is a value between 0 and 1 that will add some randomness to the waiting time.multiplier
is the factor to multiply the waiting time between each attempt. (only used forexponential
)
Internally, the retryer middleware will keep a registry of sleeper if you decide to have different configuration per intent.
Added Stamps
The Retryer Middleware is going to add:
-
type RetriedStamp = Stamp<{ attempt: number; errorMessage: string }, 'missive:retried'>;
Every time the middleware retries the handling of the intent.
Going further
Missive.js. MIT License.
Powered by Astro Starlight.
Inspired by Symfony Messenger