MiniTransit 1.0.0
See the version list below for details.
dotnet add package MiniTransit --version 1.0.0
NuGet\Install-Package MiniTransit -Version 1.0.0
<PackageReference Include="MiniTransit" Version="1.0.0" />
<PackageVersion Include="MiniTransit" Version="1.0.0" />
<PackageReference Include="MiniTransit" />
paket add MiniTransit --version 1.0.0
#r "nuget: MiniTransit, 1.0.0"
#:package MiniTransit@1.0.0
#addin nuget:?package=MiniTransit&version=1.0.0
#tool nuget:?package=MiniTransit&version=1.0.0
MiniTransit
MiniTransit is a lightweight, extensible .NET messaging library designed as a simpler alternative to MassTransit and NServiceBus. It provides a minimal, easy-to-understand API for message-based communication in distributed systems, with a focus on flexibility and customizability.
Features
- Simple Core API – Minimal abstractions for easy onboarding and maintenance.
- Pluggable Transports – Built-in support for In-Memory, RabbitMQ, and Azure Service Bus. Add your own by implementing
IMessageBus. - Automatic Consumer Registration – Register consumers via the builder for automatic subscription and background processing.
- Configurable Retry Policies – Built-in support for various retry strategies.
- Custom Serialization – Swap out the default JSON serializer for your own.
- .NET Standard – Works with modern .NET applications and libraries.
Getting Started
Installation
Add the core package and any transport you need:
dotnet add package MiniTransit
dotnet add package MiniTransit.RabbitMQ # Optional: RabbitMQ support
dotnet add package MiniTransit.AzureServiceBus # Optional: Azure Service Bus support
Basic Usage
1. Register MiniTransit and a Transport
Use the provided extension methods to register MiniTransit and select a transport. Configuration is done via a builder pattern:
services.AddMiniTransit((settings, builder) =>
{
builder.UseInMemory();
// Or for RabbitMQ:
// builder.UseRabbitMQ(options => { options.HostName = "localhost"; ... });
// Or for Azure Service Bus:
// builder.UseAzureServiceBus(options => { options.ConnectionString = "..."; ... });
});
2. Register Consumers Automatically
You can register consumers for automatic background subscription and processing:
services.AddMiniTransit((settings, builder) =>
{
builder.UseInMemory();
builder.AddConsumer<MyConsumer>();
builder.AddConsumer<AnotherConsumer>();
});
When using AddConsumer<T>(), MiniTransit will automatically subscribe these consumers to the appropriate message types and run them as hosted services.
3. Define a Consumer
public class MyConsumer : IConsumer<MyMessage>
{
public Task ConsumeAsync(ConsumeContext<MyMessage> context)
{
// Handle the message
return Task.CompletedTask;
}
}
4. Publish and Subscribe (Manual Subscription)
If you prefer manual subscription, you can still resolve IBus and subscribe:
var bus = serviceProvider.GetRequiredService<IBus>();
await bus.SubscribeAsync<MyMessage, MyConsumer>();
await bus.StartProcessingAsync();
await bus.PublishAsync(new MyMessage { ... });
5. Scheduling (if supported by transport)
await bus.ScheduleAsync(new MyMessage { ... }, TimeSpan.FromSeconds(10));
Retry Policy Configuration
MiniTransit supports flexible retry policies for message processing failures. Configure retry policies using the builder’s UseRetry method:
services.AddMiniTransit((settings, builder) =>
{
builder.UseInMemory();
builder.UseRetry(retry =>
{
retry.Immediate(3); // 3 immediate retries
retry.Ignore<ArgumentException>(); // Ignore specific exceptions
});
});
Supported retry strategies include:
- Immediate: Retry immediately a specified number of times.
- Interval: Retry with a fixed interval.
- Custom Intervals: Retry with custom intervals.
- Exponential Backoff: Retry with exponentially increasing intervals.
- Custom Policy: Use your own implementation.
Custom Serialization
You can replace the default JSON serializer with your own implementation:
builder.UseMessageSerializer<MyCustomSerializer>();
Transport Settings
Each transport has its own settings class for advanced configuration. See the Settings folder in each transport project for details.
RabbitMQ Example
builder.UseRabbitMQ(options =>
{
options.HostName = "localhost";
options.Port = 5672;
options.UserName = "guest";
options.Password = "guest";
options.DeadLetterOnError = true;
options.DefaultMessageTimeToLiveDays = 365;
// ...other settings
});
Azure Service Bus Example
builder.UseAzureServiceBus(options =>
{
options.ConnectionString = "<your-connection-string>";
options.CreateSubscriptions = true;
options.MaxDeliveryCount = 3;
// ...other settings
});
Extending MiniTransit
To add a new transport, implement the IMessageBus interface and provide an extension method for registration. See the MiniTransit.RabbitMQ and MiniTransit.AzureServiceBus projects for examples.
Contributing
Contributions are welcome! Please open issues or submit pull requests.
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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- MiniTransit.Abstractions (>= 1.0.0)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Options (>= 9.0.4)
- MiniTransit.Abstractions (>= 1.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MiniTransit:
| Package | Downloads |
|---|---|
|
MiniTransit.RabbitMQ
MiniTransit is a lightweight, extensible .NET messaging library. RabbitMQ MiniTransit implementation. |
|
|
MiniTransit.AzureServiceBus
MiniTransit is a lightweight, extensible .NET messaging library. Azure Service Bus MiniTransit implementation. |
GitHub repositories
This package is not used by any popular GitHub repositories.