MiniTransit 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MiniTransit --version 1.0.0
                    
NuGet\Install-Package MiniTransit -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="MiniTransit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiniTransit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MiniTransit" />
                    
Project file
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 MiniTransit --version 1.0.0
                    
#r "nuget: MiniTransit, 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 MiniTransit@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=MiniTransit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MiniTransit&version=1.0.0
                    
Install as a Cake Tool

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 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.

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.

Version Downloads Last Updated
1.1.0 351 5/5/2025
1.0.0 240 5/1/2025