PollyMassTransit 1.0.1
dotnet add package PollyMassTransit --version 1.0.1
NuGet\Install-Package PollyMassTransit -Version 1.0.1
<PackageReference Include="PollyMassTransit" Version="1.0.1" />
<PackageVersion Include="PollyMassTransit" Version="1.0.1" />
<PackageReference Include="PollyMassTransit" />
paket add PollyMassTransit --version 1.0.1
#r "nuget: PollyMassTransit, 1.0.1"
#:package PollyMassTransit@1.0.1
#addin nuget:?package=PollyMassTransit&version=1.0.1
#tool nuget:?package=PollyMassTransit&version=1.0.1
PollyMassTransit
Polly v8 producer-side resilience for MassTransit — add retry, timeout, and circuit-breaker to IBus.Publish and SendAsync in two lines.
Key differentiator: MassTransit's built-in retry only applies to consumers. This library fills the producer-side gap.
var resilient = bus.WithPolly(pipeline => pipeline
.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromSeconds(1),
BackoffType = DelayBackoffType.Exponential,
UseJitter = true,
ShouldHandle = MassTransitTransientErrors.IsTransient,
})
.AddTimeout(TimeSpan.FromSeconds(10)));
await resilient.PublishAsync(new OrderPlaced { OrderId = id }, cancellationToken);
Why PollyMassTransit?
MassTransit's retry middleware sits on the consumer pipeline — it retries message processing. When the producer (your application code publishing or sending messages) fails due to a transient broker outage, MassTransit does nothing. This library adds Polly v8 to the producer side:
| Problem | Solution |
|---|---|
RequestTimeoutException during request-reply |
Caught by MassTransitTransientErrors.IsTransient |
TimeoutException at the transport layer |
Caught by MassTransitTransientErrors.IsTransient |
HttpRequestException (HTTP transport) |
Caught by MassTransitTransientErrors.IsTransient |
TaskCanceledException timeout in transit |
Caught by MassTransitTransientErrors.IsTransient |
| Cascading failures during broker downtime | Wrap with AddCircuitBreaker |
Installation
dotnet add package PollyMassTransit
dotnet add package Polly.Core
Quick-start
1. Manual wiring
// bus is the IBus registered by services.AddMassTransit(...)
var resilient = bus.WithPolly(p => p
.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromSeconds(1),
BackoffType = DelayBackoffType.Exponential,
UseJitter = true,
ShouldHandle = MassTransitTransientErrors.IsTransient,
}));
await resilient.PublishAsync(new OrderPlaced { OrderId = orderId }, ct);
await resilient.SendAsync(new Uri("queue:orders"), new CreateOrder { ... }, ct);
2. Dependency injection
// After services.AddMassTransit(...)
builder.Services.AddPollyMassTransit(pipeline => pipeline
.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromSeconds(1),
BackoffType = DelayBackoffType.Exponential,
UseJitter = true,
ShouldHandle = MassTransitTransientErrors.IsTransient,
})
.AddTimeout(TimeSpan.FromSeconds(10)));
public class OrderService(ResilientBus bus)
{
public Task PlaceOrderAsync(Order order, CancellationToken ct)
=> bus.PublishAsync(new OrderPlaced { OrderId = order.Id }, ct);
}
API reference
| Member | Description |
|---|---|
ResilientBus.Inner |
The underlying IBus |
PublishAsync<T>(message, ct) |
Publishes a message through the pipeline |
PublishAsync<T>(message, pipe, ct) |
Publishes with a pipe configuration through the pipeline |
SendAsync<T>(address, message, ct) |
Sends to an endpoint through the pipeline |
ExecuteAsync<T>(operation, ct) |
Runs any IBus operation through the pipeline |
MassTransitTransientErrors.IsTransient |
PredicateBuilder for RequestTimeoutException, TimeoutException, HttpRequestException, TaskCanceledException |
bus.WithPolly(pipeline) |
Wraps IBus with a pre-built pipeline |
bus.WithPolly(configure) |
Builds pipeline inline and wraps the bus |
services.AddPollyMassTransit(configure) |
DI registration (requires IBus in DI) |
Target frameworks
.NET 6 ✅ · .NET 8 ✅ · .NET 9 ✅
Related packages
| Package | Description |
|---|---|
| PollyRabbitMQ | Polly v8 for RabbitMQ |
| PollyKafka | Polly v8 for Confluent.Kafka |
| PollyAzureServiceBus | Polly v8 for Azure Service Bus |
| PollyAzureEventHub | Polly v8 for Azure Event Hubs |
| PollySignalR | Polly v8 for SignalR |
| PollyGrpc | Polly v8 for gRPC |
| PollyRedis | Polly v8 for StackExchange.Redis |
| PollyEFCore | Polly v8 for Entity Framework Core |
| PollyDapper | Polly v8 for Dapper |
| PollyMongo | Polly v8 for MongoDB |
| PollyNpgsql | Polly v8 for Npgsql (PostgreSQL) |
| PollySqlClient | Polly v8 for Microsoft.Data.SqlClient |
| PollyCosmosDb | Polly v8 for Azure Cosmos DB |
| PollyAzureBlob | Polly v8 for Azure Blob Storage |
| PollyOpenAI | Polly v8 for OpenAI .NET SDK |
| PollyMediatR | Polly v8 for MediatR |
| PollyHealthChecks | Polly v8 for ASP.NET Core Health Checks |
| PollySendGrid | Polly v8 for SendGrid |
| PollyAzureTableStorage | Polly v8 for Azure Table Storage |
| PollyMailKit | MailKit SMTP email client |
| PollyAzureQueueStorage | Azure Queue Storage QueueClient |
| PollyHangfire | Hangfire IBackgroundJobClient |
| PollyBackoff | Polly v8 backoff helpers |
💼 Need .NET consulting?
The author of this package is available for consulting on Polly v8 resilience, Azure cloud architecture, and clean .NET design.
→ solidqualitysolutions.com · LinkedIn
License
MIT © Justin Bannister
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- MassTransit (>= 8.5.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.17)
- Polly.Core (>= 8.7.0)
-
net8.0
- MassTransit (>= 8.5.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.17)
- Polly.Core (>= 8.7.0)
-
net9.0
- MassTransit (>= 8.5.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.17)
- Polly.Core (>= 8.7.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.1: Fix package icon (was showing an incorrect/placeholder image). 1.0.0: Initial release. ResilientBus wraps IBus in a Polly v8 ResiliencePipeline for producer-side resilience. Includes MassTransitTransientErrors predicate covering RequestTimeoutException, TimeoutException, HttpRequestException, and TaskCanceledException. Supports net6.0, net8.0, and net9.0.