RabbitSharp 2.0.2

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

RabbitSharp

A high-performance, highly customizable RabbitMQ Pub/Sub library for .NET 6+ applications with built-in retry mechanisms and dead letter queue support.

Features

  • ✅ Full Pub/Sub pattern implementation
  • ✅ Compatible with .NET 6+
  • ✅ Highly customizable configuration
  • ✅ Built-in retry mechanisms with exponential backoff
  • ✅ Dead letter queue support
  • ✅ Network recovery and connection resilience
  • ✅ Configurable heartbeat intervals
  • ✅ Multiple host support for high availability
  • ✅ Flexible exchange and routing configuration
  • ✅ Convention-based naming with customizable overrides
  • ✅ Pre-configured setups for different environments

Installation

dotnet add package RabbitSharp

Quick Start

  1. Configure your appsettings.json
{
  "BrokerOptions": {
    "TryConnectMaxRetries": 5,
    "NetworkRecoveryIntervalInSeconds": 10,
    "HeartbeatIntervalSeconds": 60,
    "Hosts": [ "localhost" ],
    "Username": "guest",
    "Password": "guest",
    "VirtualHost": "/"
  }
}
  1. Register RabbitSharp in Program.cs
var brokerOptions = builder.Configuration.GetSection(nameof(BrokerOptions)).Get<BrokerOptions>() ?? new BrokerOptions();
builder.Services.AddRabbitSharp(options =>
{
    options.Username = brokerOptions.Username;
    options.Password = brokerOptions.Password;
    options.VirtualHost = brokerOptions.VirtualHost;
    options.Hosts = brokerOptions.Hosts;
});

With Resilience Configuration:

var brokerOptions = builder.Configuration.GetSection(nameof(BrokerOptions)).Get<BrokerOptions>() ?? new BrokerOptions();
builder.Services.AddRabbitSharp(options =>
{
    options.Username = brokerOptions.Username;
    options.Password = brokerOptions.Password;
    options.VirtualHost = brokerOptions.VirtualHost;
    options.Hosts = brokerOptions.Hosts;
}, busResilienceOptions =>
{
    busResilienceOptions.InitialDeliveryRetryDelay = TimeSpan.FromSeconds(1);
    busResilienceOptions.MaxDeliveryRetryDelay = TimeSpan.FromSeconds(10);
    busResilienceOptions.MaxDeliveryRetryAttempts = 3;
});
  1. Create your message class
public class EventSimple : IMessage
{
    public EventSimple(Guid correlationId)
    {
        CorrelationId = correlationId;
    }
    
    public EventSimple()
    {
        CorrelationId = Guid.NewGuid();
    }
    
    public Guid CorrelationId { get; init; }
}
  1. Publish messages
using var scope = serviceScopeFactory.CreateScope();
var bus = scope.ServiceProvider.GetRequiredService<IBus>();
var eventSimple = new EventSimple(Guid.NewGuid());
await bus.PublishAsync(eventSimple);

Publishing Messages

Basic Publishing The simplest way to publish a message. When using basic publishing, RabbitSharp automatically creates:

  • Exchange: Topic type with name based on your message class name (e.g., "EventSimple")
  • Routing Key: MessageName.# pattern (e.g., "EventSimple.#")
using var scope = serviceScopeFactory.CreateScope();
var bus = scope.ServiceProvider.GetRequiredService<IBus>();
var eventSimple = new EventSimple(Guid.NewGuid());
await bus.PublishAsync(eventSimple);

Advanced Publishing with Custom Options For more control over exchange configuration and routing:

using var scope = serviceScopeFactory.CreateScope();
var bus = scope.ServiceProvider.GetRequiredService<IBus>();

var options = new PublisherOptionsBuilder()
    .WithExchange(exchange =>
    {
        exchange.WithName("publisher.event-simple");
        exchange.WithType(ExchangeTypeEnum.Direct);
        exchange.AsDurable();
        exchange.WithArgument("alternate-exchange", "unrouted.exchange");
    })
    .WithRoutingKey("event.simple")
    .Build();

var eventSimple = new EventSimple(Guid.NewGuid());
await bus.PublishAsync(options, eventSimple);

Message Requirements

public sealed record YourMessage : IMessage
{
    public Guid CorrelationId { get; init; }
    
    // Your message properties here
}
  1. Subscribing to Messages Basic Subscription (Convention-Based) The simplest way to consume messages. RabbitSharp will automatically connect to a Topic exchange named after your message class:
private void SetSubscribers()
{
    bus.SubscribeAsync<EventSimple>("subscriber.event-simple", HandleEventAsync);
}

Advanced Subscription with Custom Configuration For full control over queue and exchange configuration:

private void SetSubscribers()
{
    var options = new BusInfrastructureBuilder("subscriber.event-simple")
        .WithExchange(exchange =>
        {
            exchange.WithName("publisher.event-simple");
            exchange.WithType(ExchangeTypeEnum.Direct);
            exchange.AsDurable();
            exchange.WithArgument("alternate-exchange", "unrouted.exchange");
        })
        .WithMainQueue(queue =>
        {
            queue.AsDurable();
            queue.WithMaxLength(10000);
            queue.WithMaxPriority(10);
            queue.WithOverflowBehavior(OverFlowStrategyEnum.RejectPublish);
            queue.WithTTL(TimeSpan.FromDays(30));
        })
        .WithRoutingKey("event.simple")
        .Build();
        
    bus.SubscribeAsync<EventSimple>(options, HandleEventAsync);
}

Environment-Specific Presets

RabbitSharp provides pre-configured setups for different scenarios:

// For development environments
var devOptions = new BusInfrastructureBuilder("my-queue")
    .ForDevelopment()
    .Build();

// For high-throughput scenarios
var highThroughputOptions = new BusInfrastructureBuilder("my-queue")
    .ForHighThroughput()
    .Build();

Exchange Types

RabbitSharp supports the following exchange types:

  • Topic: Pattern-based routing (default for convention-based publishing)
  • Direct: Exact routing key matching
  • Fanout: Broadcast to all bound queues

Best Practices

  • RabbitSharp comes with sensible defaults following RabbitMQ best practices
  • Even without manual configuration, retry queues and dead letter queues are automatically set up
Product 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 is compatible.  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. 
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
2.0.2 90 10/4/2025
2.0.1 96 10/3/2025

Initial release with full Pub/Sub support, retry mechanisms, and dead letter queues.