EasyCore.RabbitMQ 8.3.1

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

πŸ‡ EasyCore.RabbitMQ

EasyCore.RabbitMQ is a RabbitMQ infrastructure client for .NET 8. Built on RabbitMQ.Client, it provides DI registration, connect, publish, subscribe, and Ack/Nack. It is not tied to IEvent / EventBus β€” use it standalone, or via the EasyCore.EventBus.RabbitMQ adapter.

.NET C# RabbitMQ License Version


🌍 Language


πŸ“š Table of Contents


1. 🎯 Positioning

Scenario Fit?
Byte-level publish/subscribe against RabbitMQ βœ…
Fine-grained AMQP headers and Ack/Nack βœ…
Unified IEvent + handler discovery (EDA) ❌ β†’ use EasyCore.EventBus.RabbitMQ
In-process local events ❌ β†’ use EasyCore.EventBus local bus

1.1 Design Principles

Principle Meaning
Infrastructure layer Connection, topology, and raw bytes β€” no business event model
Standalone No dependency on the EasyCore.EventBus core package
Adapter-friendly The EventBus RabbitMQ adapter reuses this client

2. Relation to EventBus

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  App code (any payload)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ IRabbitMQClient
               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  EasyCore.RabbitMQ (this)   β”‚  ← infrastructure client
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ RabbitMQ.Client
               β–Ό
          RabbitMQ Broker

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ EasyCore.EventBus.RabbitMQ  β”‚  ← adapter: IEvent / Handler
β”‚   └── uses this client      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Package Role
EasyCore.RabbitMQ Generic AMQP client (this package)
EasyCore.EventBus.RabbitMQ Maps EventBus IEvent onto RabbitMQ

3. βš™ Requirements

Item Requirement
.NET 8.0+
Dependency RabbitMQ.Client 6.8.x (brought by this package)
Broker Reachable RabbitMQ instance

4. πŸ“₯ Installation

dotnet add package EasyCore.RabbitMQ

5. ⚑ Quick Start

5️⃣.1️⃣ Register DI

using EasyCore.RabbitMQ;

builder.Services.AddEasyCoreRabbitMQ(o =>
{
    o.HostName = "localhost";
    o.UserName = "guest";
    o.Password = "guest";
    o.Port = 5672;
    o.ExchangeName = "EasyCore.EventBus";
    o.ExchangeType = "topic";
    o.VirtualHost = "/";
});

5️⃣.2️⃣ Publish

public sealed class OrderPublisher
{
    private readonly IRabbitMQClient _client;

    public OrderPublisher(IRabbitMQClient client) => _client = client;

    public async Task PublishAsync(string orderId, CancellationToken ct = default)
    {
        await _client.ConnectAsync(ct);

        var body = Encoding.UTF8.GetBytes($$"""{"orderId":"{{orderId}}"}""");
        var headers = new Dictionary<string, object>
        {
            ["x-message-type"] = "OrderCreated"
        };

        await _client.PublishAsync(
            routingKey: "order.created",
            body: body,
            headers: headers,
            cancellationToken: ct);
    }
}

5️⃣.3️⃣ Subscribe with Ack / Nack

public sealed class OrderConsumer : BackgroundService
{
    private readonly IRabbitMQClient _client;

    public OrderConsumer(IRabbitMQClient client) => _client = client;

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        await _client.ConnectAsync(stoppingToken);

        await _client.SubscribeAsync(
            routingKeys: new[] { "order.created", "order.updated" },
            handler: async (msg, ct) =>
            {
                try
                {
                    var json = Encoding.UTF8.GetString(msg.Body.Span);
                    // handle business…
                    _client.Ack(msg.DeliveryTag);
                }
                catch
                {
                    _client.Nack(msg.DeliveryTag, requeue: true);
                }

                await Task.CompletedTask;
            },
            cancellationToken: stoppingToken);
    }
}

RabbitMQDeliveredMessage fields: RoutingKey, Body, Headers, DeliveryTag, CorrelationId.


6. 🧩 API Overview

Member Description
AddEasyCoreRabbitMQ(Action<RabbitMQOptions>) DI: Options, connection factory, IRabbitMQClient
ConnectAsync Connect and declare the configured exchange
PublishAsync(routingKey, body, headers?) Publish to the exchange (with confirms)
SubscribeAsync(routingKeys, handler) Declare queue, bind keys, start consuming
Ack(deliveryTag) Acknowledge
Nack(deliveryTag, requeue) Reject; requeue when requeue is true

IRabbitMQClient implements IAsyncDisposable β€” dispose on shutdown.


7. Options (RabbitMQOptions)

Property Type Default Description
HostName string localhost Host; comma-separated for clusters
UserName string guest Username
Password string guest Password
Port int 5672 AMQP port
ExchangeName string EasyCore.EventBus Exchange name
QueueName string EasyCore.Queue Queue name suffix (combined with AppName)
ExchangeType string topic topic / direct / fanout / headers
VirtualHost string / Virtual host
MessageTTL int 864000000 Queue message TTL (ms, ~10 days)
QueueMode string? null Optional, e.g. lazy
Durable bool true Durable queue
Exclusive bool false Exclusive queue
AutoDelete bool false Auto-delete when unused
QueueType string? null Optional, e.g. quorum
AppName string? null Queue name prefix; entry assembly when null

8. ❓ FAQ

Q: This package vs EasyCore.EventBus.RabbitMQ?
A: Use the EventBus adapter for IEvent, handlers, and retries. Use this package for raw byte publish/subscribe.

Q: Must I call ConnectAsync first?
A: Yes β€” connect before publish or subscribe so the connection and exchange are ready.

Q: How is the subscription queue named?
A: From AppName (or entry assembly) plus QueueName, then bound to the given routing keys.

Q: When to requeue on Nack?
A: Transient failures: requeue: true. Poison messages: false (or dead-letter) to avoid loops.

Q: Multiple hosts?
A: Pass comma-separated hosts in HostName; failover follows RabbitMQ.Client behavior.


9. πŸ“„ License

MIT β€” see the repository LICENSE, or the NuGet package metadata.


🀝 Contributing

Issues and PRs are welcome. After changing this package, verify EasyCore.EventBus.RabbitMQ and related demos.

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 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on EasyCore.RabbitMQ:

Package Downloads
EasyCore.EventBus.RabbitMQ

.NET Core EventBus distributed transport based on RabbitMQ.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.3.1 120 8/4/2026
8.3.0 132 7/21/2026
8.0.0 132 7/18/2026