PollyRabbitMQ 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PollyRabbitMQ --version 1.0.0
NuGet\Install-Package PollyRabbitMQ -Version 1.0.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="PollyRabbitMQ" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PollyRabbitMQ" Version="1.0.0" />
<PackageReference Include="PollyRabbitMQ" />
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 PollyRabbitMQ --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PollyRabbitMQ, 1.0.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 PollyRabbitMQ@1.0.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=PollyRabbitMQ&version=1.0.0
#tool nuget:?package=PollyRabbitMQ&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PollyRabbitMQ
PollyRabbitMQ wraps RabbitMQ.Client v7 channels with a Polly v8 resilience pipeline — retry, circuit breaker, and timeout — so your messaging code handles transient broker failures transparently.
Features
- 🔁 Retry with exponential back-off + jitter on transient RabbitMQ exceptions
- ⚡ Circuit Breaker to stop hammering a degraded broker
- ⏱️ Timeout per operation
- 🔄 Optional channel recreation between retries when the broker closes the channel
- 🧩 Works with any
IChannelfrom RabbitMQ.Client 7+ - 💉 Dependency Injection via
IServiceCollectionextensions
Installation
dotnet add package PollyRabbitMQ
Quick Start
using PollyRabbitMQ;
using RabbitMQ.Client;
// Create a connection the normal way
var factory = new ConnectionFactory { HostName = "localhost" };
await using var connection = await factory.CreateConnectionAsync();
// Wrap a channel with Polly resilience
var resilientChannel = await connection.CreateResilientChannelAsync();
// Declare a queue
await resilientChannel.QueueDeclareAsync("my-queue");
// Publish a message — retried automatically on transient failures
var body = Encoding.UTF8.GetBytes("Hello, World!");
await resilientChannel.BasicPublishAsync("", "my-queue", body);
// Consume a message
var result = await resilientChannel.BasicGetAsync("my-queue");
if (result is not null)
{
Console.WriteLine(Encoding.UTF8.GetString(result.Body.Span));
await resilientChannel.BasicAckAsync(result.DeliveryTag);
}
Dependency Injection
builder.Services.AddResilientRabbitMqChannel(connection, options =>
{
options.MaxRetries = 5;
options.BaseDelay = TimeSpan.FromMilliseconds(200);
options.MaxDelay = TimeSpan.FromSeconds(30);
options.OperationTimeout = TimeSpan.FromSeconds(10);
options.CircuitBreakerFailureRatio = 0.5;
options.CircuitBreakerMinimumThroughput = 5;
options.CircuitBreakerBreakDuration = TimeSpan.FromSeconds(30);
options.RecreateChannelOnFailure = true;
});
// Inject ResilientChannel into your service
public class MyConsumer(ResilientChannel channel) { ... }
Options
| Option | Default | Description |
|---|---|---|
MaxRetries |
3 |
Number of retries (0 = no retries) |
BaseDelay |
200 ms |
Starting delay for exponential back-off |
MaxDelay |
30 s |
Maximum delay between retries |
OperationTimeout |
10 s |
Timeout per individual operation |
CircuitBreakerFailureRatio |
0.5 |
Failure ratio to open the circuit |
CircuitBreakerMinimumThroughput |
5 |
Min calls before CB evaluates |
CircuitBreakerSamplingDuration |
30 s |
Sliding window for CB evaluation |
CircuitBreakerBreakDuration |
30 s |
How long the circuit stays open |
RecreateChannelOnFailure |
false |
Recreate the channel between retries |
Transient Exceptions
The following RabbitMQ exceptions are treated as transient and trigger retry:
AlreadyClosedException— channel closed by brokerOperationInterruptedException— operation interruptedBrokerUnreachableException— broker temporarily unreachableConnectFailureException— initial connection failed
Non-transient exceptions propagate immediately without retry.
Channel Recreation
When RecreateChannelOnFailure = true and a channel factory is supplied, the channel is recreated between retries:
var channel = await connection.CreateResilientChannelAsync(
options: new PollyRabbitMqOptions { RecreateChannelOnFailure = true },
channelFactory: ct => connection.CreateChannelAsync(cancellationToken: ct));
Related Packages
| Package | Purpose |
|---|---|
| PollyBackoff | Polly v8 advanced back-off strategies |
| PollyChaos | Chaos engineering for Polly v8 |
| PollyMediatR | Polly resilience for MediatR handlers |
| PollyEFCore | Polly resilience for Entity Framework Core |
| PollyHealthChecks | ASP.NET Core health checks for Polly policies |
| PollyOpenAI | Polly resilience for OpenAI / Azure OpenAI |
| PollyRedis | Polly resilience for StackExchange.Redis |
| PollySignalR | Polly resilience for SignalR clients |
| PollyGrpc | Polly resilience for gRPC channels |
| PollyKafka | Polly resilience for Confluent Kafka |
| PollyAzureServiceBus | Polly resilience for Azure Service Bus |
| Polly.Contrib.Caching | Polly v8 caching policy |
| Polly.Contrib.Bulkhead | Polly v8 bulkhead policy |
| Polly.Contrib.OpenTelemetry | OpenTelemetry instrumentation for Polly |
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Polly.Core (>= 8.7.0)
- RabbitMQ.Client (>= 7.2.1)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Polly.Core (>= 8.7.0)
- RabbitMQ.Client (>= 7.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.