Verbara.Sdk.Resilience 2.10.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Verbara.Sdk.Resilience --version 2.10.0
                    
NuGet\Install-Package Verbara.Sdk.Resilience -Version 2.10.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Verbara.Sdk.Resilience" Version="2.10.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Verbara.Sdk.Resilience" Version="2.10.0" />
                    
Directory.Packages.props
<PackageReference Include="Verbara.Sdk.Resilience" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Verbara.Sdk.Resilience --version 2.10.0
                    
#r "nuget: Verbara.Sdk.Resilience, 2.10.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Verbara.Sdk.Resilience@2.10.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Verbara.Sdk.Resilience&version=2.10.0
                    
Install as a Cake Addin
#tool nuget:?package=Verbara.Sdk.Resilience&version=2.10.0
                    
Install as a Cake Tool

Verbara.Sdk.Resilience

Composable resilience primitives for .NET. AOT-safe, zero reflection, TimeProvider-based for testability. No Polly dependency. MIT licensed.

What it does

  • Circuit breaker — per-key CircuitBreakerState with classic closed → open → half-open → closed cycle: once the open window has elapsed one call is admitted as the probe and every other is rejected until its result is recorded; a failed probe re-opens the circuit for a full window, a successful one closes it. Thread-safe via Interlocked/Volatile; no locks.
  • Retry with exponential backoff — configurable maxAttempts (capped at 10) and baseDelay with ±20% deterministic jitter.
  • Per-attempt timeout — wraps action in linked CancellationTokenSource that honours both caller token and timeout.
  • Fluent builder — compose any subset of the three primitives via ResiliencePolicyBuilder and call Build().
  • First-class diagnostics via System.Diagnostics.Metrics (meter name Verbara.Sdk.Resilience): retry.attempts, circuit.opened, circuit.closed, timeout.fired, circuit.state observable gauge.

No external runtime dependencies beyond Microsoft.Extensions.* abstractions. Trim-safe.

Install

dotnet add package Verbara.Sdk.Resilience

Quick start

using Verbara.Sdk.Resilience;
using Verbara.Sdk.Resilience.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

// 1) Register a default policy (or a no-op if configure is null).
var services = new ServiceCollection();
services.AddVerbaraResilience(b => b
    .WithCircuitBreaker(threshold: 5, openDuration: TimeSpan.FromSeconds(30))
    .WithRetry(maxAttempts: 3, baseDelay: TimeSpan.FromMilliseconds(100))
    .WithTimeout(TimeSpan.FromSeconds(5)));

// 2) Resolve + execute.
var provider = services.BuildServiceProvider();
var policy = provider.GetRequiredService<ResiliencePolicy>();

var result = await policy.ExecuteAsync(
    key: "payment-gateway",
    action: async ct =>
    {
        // Work that may throw (network call, DB write, external API, etc.).
        return await CallPaymentGatewayAsync(ct);
    },
    ct: CancellationToken.None);

Directly (without DI)

var policy = new ResiliencePolicyBuilder()
    .WithRetry(3, TimeSpan.FromMilliseconds(100))
    .WithTimeout(TimeSpan.FromSeconds(5))
    .Build();

await policy.ExecuteAsync("key", async ct => { /* work */ return 42; }, ct: default);

Observability

Meter name: Verbara.Sdk.Resilience. Enrol in OpenTelemetry:

builder.Services.AddOpenTelemetry()
    .WithMetrics(m => m.AddMeter("Verbara.Sdk.Resilience"));

Or transparently via AddVerbaraOpenTelemetry().WithAllSources().

Instruments emitted:

Instrument Kind Tags
retry.attempts Counter<long> key
circuit.opened Counter<long>, one per opening: a trip from closed, or a failed probe key
circuit.closed Counter<long>, one per close: a successful probe, or a late success on an open circuit key
timeout.fired Counter<long> key
circuit.state ObservableGauge<int> (0=closed, 1=half-open, 2=open), the current state when observed key

circuit.state reports the state a key's circuit is in when the gauge is observed, from its policy's open window and clock, with no later call needed. 2 (open): the circuit is open within its window, and a call now is rejected with CircuitBreakerOpenException. 1 (half-open): the open window has elapsed and no probe result has been recorded since, either because no call has come yet, in which case the next call is admitted as the probe, or because the probe is in flight, in which case every other call is rejected. 0 (closed): anything else, including failures below the threshold. A failed probe reads 2 for a full window from that failure, whatever the threshold; a successful one reads 0. A probe that reports nothing (its caller cancelled it) reads 1 and holds the circuit shut for at most one more window. Under a failing dependency with traffic the circuit cycles through 2 and 1 with one attempt per window, so an unbroken 2 does not measure an outage: circuit.opened counts openings. A key is reported from its first success, rejection or trip; where two policies share a key, the gauge follows the one that reported it last.

ResiliencePolicy.GetCircuitState(key) returns the same reading as a ResilienceMetrics.CircuitStateValue for that policy's own circuit, so a health check needs no MeterListener. A key with no circuit in the policy, and any key of a policy without a circuit breaker, reads Closed, because its next call is admitted. Neither the read nor the gauge changes the circuit, and the read does not make a key appear on the gauge.

Testing

TimeProvider.System is the default clock. Inject FakeTimeProvider (Microsoft.Extensions.TimeProvider.Testing) via WithTimeProvider(fakeTimeProvider) for deterministic backoff delays and circuit open-duration testing.

License

MIT. Part of the Verbara.Sdk project.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Verbara.Sdk.Resilience:

Package Downloads
Verbara.Sdk.Ami

Asterisk Manager Interface (AMI) client - actions, events, responses and protocol handling

Verbara.Sdk.Ari

Asterisk REST Interface (ARI) client - HTTP + WebSocket for Stasis applications

Verbara.Sdk.Push.Webhooks

Verbara.Sdk.Push.Webhooks - outbound HTTP webhook delivery for Verbara.Sdk.Push. Consumes events from the Push bus, matches against WebhookSubscription topic patterns, POSTs with HMAC-SHA256 signature and exponential retry/backoff. AOT-safe.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.10.1 2,018 11/17/2026
2.10.0 395 11/16/2026
2.9.0 2,982 10/29/2026
2.8.0 3,098 10/9/2026
2.7.0 844 10/3/2026
2.6.1 578 9/30/2026
2.6.0 818 9/24/2026
2.5.3 743 9/13/2026
2.5.2 358 9/13/2026
2.5.1 346 9/12/2026
2.5.0 258 8/25/2026
2.4.0 2,352 7/27/2026
2.3.2 779 7/20/2026
2.3.1 413 7/14/2026
2.3.0 528 7/6/2026
2.2.1 1,174 5/23/2026
2.2.0 267 5/20/2026
2.1.2 266 5/8/2026
2.1.1 240 5/7/2026
2.1.0 228 5/7/2026
Loading failed