Verbara.Sdk.Resilience
2.2.1
dotnet add package Verbara.Sdk.Resilience --version 2.2.1
NuGet\Install-Package Verbara.Sdk.Resilience -Version 2.2.1
<PackageReference Include="Verbara.Sdk.Resilience" Version="2.2.1" />
<PackageVersion Include="Verbara.Sdk.Resilience" Version="2.2.1" />
<PackageReference Include="Verbara.Sdk.Resilience" />
paket add Verbara.Sdk.Resilience --version 2.2.1
#r "nuget: Verbara.Sdk.Resilience, 2.2.1"
#:package Verbara.Sdk.Resilience@2.2.1
#addin nuget:?package=Verbara.Sdk.Resilience&version=2.2.1
#tool nuget:?package=Verbara.Sdk.Resilience&version=2.2.1
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
CircuitBreakerStatewith classic closed → open → half-open → closed cycle. Thread-safe viaInterlocked/Volatile; no locks. - Retry with exponential backoff — configurable
maxAttempts(capped at 10) andbaseDelaywith ±20% deterministic jitter. - Per-attempt timeout — wraps action in linked
CancellationTokenSourcethat honours both caller token and timeout. - Fluent builder — compose any subset of the three primitives via
ResiliencePolicyBuilderand callBuild(). - First-class diagnostics via
System.Diagnostics.Metrics(meter nameVerbara.Sdk.Resilience):retry.attempts,circuit.opened,circuit.closed,timeout.fired,circuit.stateobservable 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.AddAsteriskResilience(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 AddAsteriskOpenTelemetry().WithAllSources().
Instruments emitted:
| Instrument | Kind | Tags |
|---|---|---|
retry.attempts |
Counter<long> | key |
circuit.opened |
Counter<long> | key |
circuit.closed |
Counter<long> | key |
timeout.fired |
Counter<long> | key |
circuit.state |
ObservableGauge<int> (0=closed, 1=half-open, 2=open) | key |
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 | Versions 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Options (>= 10.0.8)
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.