Version

Welcome to Kampute.Resilience

Network calls time out, databases drop connections, and services ask clients to slow down. Many of these failures clear on their own, and the operation succeeds when it is tried again a moment later. Kampute.Resilience retries such operations for you: you describe how long to wait between attempts, when to give up, and which failures are worth another try, and it runs your operation under those rules.

The package targets netstandard2.0 and net10.0 and has no package dependencies.

Highlights

Install

dotnet add package Kampute.Resilience

First Retry

This example retries an asynchronous operation up to five times when it throws TimeoutException. It waits about one second before the first retry and doubles the delay after that, varying each delay by up to 20 percent. RunOperationAsync stands for your own operation.

using System;
using Kampute.Resilience;

var retry = RetryStrategies
    .Exponential(TimeSpan.FromSeconds(1))
    .WithJitter(0.2)
    .WithMaxRetries(5)
    .RetryOn<TimeoutException>();

var result = await retry.ExecuteAsync(ct => RunOperationAsync(ct));

Other exceptions reach the caller at once. If every retry fails, the last TimeoutException is rethrown with its original stack trace. The retry policy can be stored and reused for any number of operations, including concurrent ones.

How It Fits Together

Building blockAnswersStart with
StrategyHow long to wait before each retry, and when to stop.RetryStrategies
PolicyWhich exceptions and results to retry, and what to do at each retry.RetryPolicy
SessionWhether and when to retry in a retry loop that you write yourself.RetrySession

Most applications need only a strategy and a policy. A strategy can also run an operation directly, retrying every exception except caller cancellation.

Learn More