EasyCore.RabbitMQ
8.3.0
See the version list below for details.
dotnet add package EasyCore.RabbitMQ --version 8.3.0
NuGet\Install-Package EasyCore.RabbitMQ -Version 8.3.0
<PackageReference Include="EasyCore.RabbitMQ" Version="8.3.0" />
<PackageVersion Include="EasyCore.RabbitMQ" Version="8.3.0" />
<PackageReference Include="EasyCore.RabbitMQ" />
paket add EasyCore.RabbitMQ --version 8.3.0
#r "nuget: EasyCore.RabbitMQ, 8.3.0"
#:package EasyCore.RabbitMQ@8.3.0
#addin nuget:?package=EasyCore.RabbitMQ&version=8.3.0
#tool nuget:?package=EasyCore.RabbitMQ&version=8.3.0
π 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 theEasyCore.EventBus.RabbitMQadapter.
π Language
- Chinese: README.md
- English (this document)
π Table of Contents
- 1. Positioning
- 2. Relation to EventBus
- 3. Requirements
- 4. Installation
- 5. Quick Start
- 6. API Overview
- 7. Options (
RabbitMQOptions) - 8. FAQ
- 9. License
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 | 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 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- RabbitMQ.Client (>= 6.8.1)
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.