RabbitWire 1.0.3

dotnet add package RabbitWire --version 1.0.3
                    
NuGet\Install-Package RabbitWire -Version 1.0.3
                    
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="RabbitWire" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RabbitWire" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="RabbitWire" />
                    
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 RabbitWire --version 1.0.3
                    
#r "nuget: RabbitWire, 1.0.3"
                    
#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 RabbitWire@1.0.3
                    
#: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=RabbitWire&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=RabbitWire&version=1.0.3
                    
Install as a Cake Tool

πŸ‡ RabbitWire

NuGet License

RabbitWire is a lightweight .NET library that simplifies RabbitMQ integration using MassTransit. It provides a convention-based setup for producers and consumers, automatic queue naming with environment prefixes, built-in retry policies, and a clean service abstraction β€” so you can focus on your business logic instead of messaging plumbing.


✨ Features

  • One-line setup β€” Register RabbitMQ with a single AddRabbitWire() call.
  • Convention-based queue naming β€” Queue names are automatically derived from consumer class names with a configurable prefix (e.g. dev.productcreated.event.v1).
  • Environment-aware prefixes β€” Use prefixes like dev, test, stage, prod to isolate queues per environment.
  • Built-in retry & error handling β€” Exponential backoff and interval-based retries are configured out of the box.
  • SSL/TLS support β€” Optionally enable TLS 1.2 for secure connections.
  • Multiple consumers β€” Pass as many consumer types as you need in a single registration call.
  • Clean send abstraction β€” Use IRabbitWireService to send messages to any queue URI.

πŸ“¦ Installation

dotnet add package RabbitWire

Or via the NuGet Package Manager:

Install-Package RabbitWire

πŸš€ Quick Start

1. Add Configuration

Add the following section to your appsettings.json:

{
  "RabbitMqTransportOptions": {
    "Host": "localhost",
    "VHost": "/",
    "User": "guest",
    "Pass": "guest",
    "Port": 5672,
    "UseSsl": false,
    "Prefix": "dev"
  }
}
Property Description
Host RabbitMQ server hostname.
VHost Virtual host (default /).
User RabbitMQ username.
Pass RabbitMQ password.
Port RabbitMQ port (default 5672).
UseSsl Set to true to enable TLS 1.2.
Prefix Environment prefix for queue names (e.g. dev, test, prod).

2. Register RabbitWire in Program.cs

builder.Services.AddRabbitWire(
    configuration,
    typeof(ProductCreatedConsumer),
    typeof(ProductUpdatedConsumer)
);

AddRabbitWire accepts multiple consumer types via params. Each consumer is automatically wired to a receive endpoint with a queue name derived from its class name and the configured prefix.


πŸ“– Usage

Sending Messages

RabbitWire provides IRabbitWireService for sending messages to RabbitMQ queues.

Create a small abstraction that maps your domain events to queue URIs. This keeps queue addresses centralized and easy to maintain.

IQueueUriProvider.cs

public interface IQueueUriProvider
{
    Uri ProductCreatedMessage { get; }
    Uri ProductUpdatedMessage { get; }
    Uri ProductDeletedMessage { get; }
}

QueueUriProvider.cs

using MessageBroker.RabbitMq;
using Microsoft.Extensions.Options;

public class QueueUriProvider : IQueueUriProvider
{
    private readonly RabbitWireConfig _rabbitMqOptions;

    public QueueUriProvider(IOptions<RabbitWireConfig> options)
    {
        _rabbitMqOptions = options.Value;
    }

    public Uri ProductCreatedMessage =>
        new Uri($"queue:{_rabbitMqOptions.Prefix}.mystore.productcreated.event.v1");

    public Uri ProductUpdatedMessage =>
        new Uri($"queue:{_rabbitMqOptions.Prefix}.mystore.productupdated.event.v1");

    public Uri ProductDeletedMessage =>
        new Uri($"queue:{_rabbitMqOptions.Prefix}.mystore.productdeleted.event.v1");
}

Register it in Program.cs:

builder.Services.AddScoped<IQueueUriProvider, QueueUriProvider>();
Send a Message from a Handler
public class ProductCreateHandler : IRequestHandler<CreateProductCommand, bool>
{
    private readonly IRabbitWireService _bus;
    private readonly IQueueUriProvider _queueUri;

    public ProductCreateHandler(IRabbitWireService bus, IQueueUriProvider queueUri)
    {
        _bus = bus;
        _queueUri = queueUri;
    }

    public async Task<bool> Handle(CreateProductCommand request, CancellationToken cancellationToken)
    {
        var productCreatedEvent = new ProductCreatedEvent
        {
            Id = 1,
            Name = "Xbox",
            Price = 480.00m
        };

        await _bus.Send(productCreatedEvent, _queueUri.ProductCreatedMessage, cancellationToken);

        return true;
    }
}

Consuming Messages

Create a consumer class that implements MassTransit's IConsumer<T>:

public class ProductCreatedConsumer : IConsumer<ProductCreatedEvent>
{
    private readonly IMediator _mediator;

    public ProductCreatedConsumer(IMediator mediator)
    {
        _mediator = mediator;
    }

    public async Task Consume(ConsumeContext<ProductCreatedEvent> context)
    {
        var product = new ProductAddedEvent
        {
            ProductId = context.Message.Id,
            Name = context.Message.Name,
            Price = context.Message.Price
        };

        await _mediator.Send(product);
    }
}

Then handle the domain event however you like β€” persist to a database, trigger notifications, etc.:

public class ProductAddedEventHandler : IRequestHandler<ProductAddedEvent, bool>
{
    private readonly MyDbContext _context;
    private readonly IMapper _mapper;

    public ProductAddedEventHandler(MyDbContext context, IMapper mapper)
    {
        _context = context;
        _mapper = mapper;
    }

    public async Task<bool> Handle(ProductAddedEvent request, CancellationToken cancellationToken)
    {
        var product = _mapper.Map<Products>(request);

        _context.Products.Add(product);
        await _context.SaveChangesAsync(cancellationToken);

        return true;
    }
}

πŸ”§ How It Works

Queue Naming Convention

RabbitWire automatically derives queue names from consumer class names using the following convention:

{Prefix}.{consumerName without "Consumer" suffix}.event.v1

Examples:

Consumer Class Prefix Generated Queue Name
ProductCreatedConsumer dev dev.productcreated.event.v1
ProductUpdatedConsumer prod prod.productupdated.event.v1
OrderShippedConsumer test test.ordershipped.event.v1

Built-in Retry Policy

Each consumer endpoint is configured with:

  • Interval retry: 3 attempts with a 3-second delay between each.
  • Exponential backoff: 3 attempts starting at 5 seconds, up to 1 hour max, with a 10-second increment.
  • Error logging via Serilog on each retry attempt.
  • ConsumerCanceledException is explicitly ignored by the retry policy.

Endpoint Defaults

Setting Default Value
PrefetchCount 5
ConfigureConsumeTopology false
AutoDelete false
ExchangeType Fanout

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Your Application                                           β”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚   Handler    │───▢│ IRabbitWireService│──── Send ───▢ πŸ‡ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜           RabbitMQβ”‚
β”‚                                                             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                               β”‚
β”‚  β”‚ ProductCreatedConsumer   │◀── Consume ──────────── πŸ‡    β”‚
β”‚  β”‚ ProductUpdatedConsumer   β”‚                        RabbitMQβ”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                               β”‚
β”‚                                                             β”‚
β”‚  Program.cs                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚
β”‚  β”‚ builder.Services.AddRabbitWire(config, consumers)β”‚       β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“š API Reference

AddRabbitWire

public static IServiceCollection AddRabbitWire(
    this IServiceCollection services,
    IConfiguration configuration,
    params Type[] consumerAssemblies)

Registers MassTransit with RabbitMQ transport and configures all provided consumer types. Reads connection settings from the RabbitMqTransportOptions configuration section.

IRabbitWireService

Method Description
Send<T>(T message, Uri queueName, CancellationToken ct) Sends a message to a specific queue URI.
Send<T>(T message, CancellationToken ct) Sends a message using MassTransit endpoint conventions.
Property Description
InstanceId Unique identifier for this service instance.
Bus The underlying MassTransit IBusControl.

RabbitWireConfig

Extends MassTransit's RabbitMqTransportOptions with:

Property Type Description
Prefix string? Environment prefix appended to queue names.

πŸ”’ SSL / TLS

To enable secure connections, set UseSsl to true in your configuration:

{
  "RabbitMqTransportOptions": {
    "Host": "rabbitmq.example.com",
    "UseSsl": true
  }
}

RabbitWire will use TLS 1.2 for the connection.


πŸ“‹ Requirements

  • .NET 10 or later
  • RabbitMQ server (local or remote)
  • MassTransit 9.x (included as a dependency)

🀝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add my feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the terms of the license included in the repository. See the LICENSE file for details.


Made with ❀️ by Casoft

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 93 2/13/2026
1.0.2 83 2/13/2026
1.0.1 83 2/13/2026
1.0.0 88 2/13/2026