SimpleTransitRabbitMQ 3.0.8
dotnet add package SimpleTransitRabbitMQ --version 3.0.8
NuGet\Install-Package SimpleTransitRabbitMQ -Version 3.0.8
<PackageReference Include="SimpleTransitRabbitMQ" Version="3.0.8" />
<PackageVersion Include="SimpleTransitRabbitMQ" Version="3.0.8" />
<PackageReference Include="SimpleTransitRabbitMQ" />
paket add SimpleTransitRabbitMQ --version 3.0.8
#r "nuget: SimpleTransitRabbitMQ, 3.0.8"
#:package SimpleTransitRabbitMQ@3.0.8
#addin nuget:?package=SimpleTransitRabbitMQ&version=3.0.8
#tool nuget:?package=SimpleTransitRabbitMQ&version=3.0.8
SimpleTransit
⚠️ Deprecated Plugin Removed: The x-delayed-message plugin is no longer used. ✅ Plugin-Free Retry: Messages now use manual retry queues with TTL/DLX.
SimpleTransit is a lightweight RabbitMQ-based messaging library for .NET, designed to be simple, explicit, and framework-friendly. It provides easy configuration of receive endpoints, retry policies, and automatic handler discovery using ASP.NET Core dependency injection.
✨ Features
- 🚀 Simple RabbitMQ integration
- 🔁 Built-in retry support with delay
- 📦 Strongly-typed events
- 🧩 Automatic handler registration via assembly scanning
- ⚙️ Minimal configuration, no magic
Installation
Install via NuGet:
dotnet add package SimpleTransitRabbitMQ
Example appsettings.json:
{
"ConnectionStrings": {
"Rabbit": "amqp://guest:guest@localhost:5672/"
}
}
Basic Usage
- Define an Event
All events must inherit from Event.
using SimpleTransit;
namespace bxgamble.Services.SimpleTransitEvents;
public class TestEvent : Event
{
public required string Message { get; set; }
}
- Configure SimpleTransit
public static WebApplicationBuilder ConfigureSimpleTransit(this WebApplicationBuilder builder)
{
builder.Services.AddSimpleTransit(
rabbitMQConnectionString: builder.Configuration.GetConnectionString("Rabbit")
?? throw new InvalidOperationException("RabbitMQ connection string is not configured."),
new SimpleTransitOptions().AddReceiveEndpoint(
new ReceiveEndpointOptions
{
Event = typeof(TestEvent),
Durable = true,
AutoDelete = false,
PrefetchCount = 100,
RetryPolicy = new RetryPolicy
{
Count = 2,
Delay = TimeSpan.FromSeconds(2)
}
}
),
typeof(Program).Assembly
);
return builder;
}
Publishing Events
SimpleTransit provides an explicit publishing abstraction via IEventBus.
IEventBus Interface
namespace SimpleTransit;
public interface IEventBus
{
Task PublishAsync<T>(T @event, CancellationToken cancellationToken)
where T : Event;
}
Publishing an Event
To publish an event, inject IEventBus and call PublishAsync.
public class TestService(IEventBus eventBus)
{
public async Task SendAsync(CancellationToken cancellationToken)
{
var @event = new TestEvent
{
Message = "Hello from SimpleTransit"
};
await eventBus.PublishAsync(@event, cancellationToken);
}
}
Event Headers
Every event in SimpleTransit contains a Header object that holds metadata about message lifecycle and failures.
Header Structure
public class Header
{
public Guid Id { get; init; }
public DateTimeOffset OccurredAt { get; init; }
public int RetryCount { get; set; }
// Optional exception info after failure
public SimpleTransitError? Error { get; set; }
}
Receive Endpoints
A Receive Endpoint defines how an event is consumed from RabbitMQ. Available Options
| Property | Description |
|---|---|
Event |
Event type handled by this endpoint |
Durable |
Whether the queue survives broker restarts |
AutoDelete |
Whether the queue is deleted when unused |
PrefetchCount |
Maximum unacknowledged messages per consumer |
RetryPolicy |
Retry behavior on handler failure |
Retry Policy
SimpleTransit supports message retry with delay.
RetryPolicy = new RetryPolicy
{
Count = 2,
Delay = TimeSpan.FromSeconds(2)
}
Behavior:
Message is retried up to Count times Delay is applied between retries After retries are exhausted, the message is dropped
Event Handlers
Handlers are discovered automatically from the provided assembly. All handlers must implement IEventHandler<TEvent>.
Example Handler
public class TestEventHandler : IEventHandler<TestEvent>
{
public Task HandleAsync(TestEvent message)
{
Console.WriteLine(message.Message);
return Task.CompletedTask;
}
}
Assembly Scanning
Handlers are registered automatically from the specified assembly:
typeof(Program).Assembly
This allows:
- Clean separation of events and handlers
- Zero manual DI registration
Acknowledgement Behavior
Messages are ACKed only after successful handler execution On exception retry policy is applied After retries, the message is NACKed
Custom JSON Serialization
SimpleTransit allows you to fully customize JSON serialization by providing your own JsonSerializerOptions.
📄 License
MIT
| 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 (>= 10.0.3)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.3)
- RabbitMQ.Client (>= 7.2.1)
- Scrutor (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.