JfYu.RabbitMQ
10.0.1
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package JfYu.RabbitMQ --version 10.0.1
NuGet\Install-Package JfYu.RabbitMQ -Version 10.0.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="JfYu.RabbitMQ" Version="10.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JfYu.RabbitMQ" Version="10.0.1" />
<PackageReference Include="JfYu.RabbitMQ" />
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 JfYu.RabbitMQ --version 10.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JfYu.RabbitMQ, 10.0.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 JfYu.RabbitMQ@10.0.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=JfYu.RabbitMQ&version=10.0.1
#tool nuget:?package=JfYu.RabbitMQ&version=10.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JfYu.RabbitMQ
Lightweight RabbitMQ client wrapper with async publishing/consuming, retry with dead-letter support, and DI integration.
Features
- Async publish with publisher confirms and throttling
- Batch publishing
- Async consumer with prefetch control
- Automatic retry via message headers; overflow to DLQ when configured
- Queue/Exchange declare and bind helpers
- DI via Microsoft.Extensions.DependencyInjection
Install
Install-Package JfYu.RabbitMQ
Configuration (appsettings.json)
{
"RabbitMQ": {
"HostName": "127.0.0.1",
"Port": 5672,
"UserName": "guest",
"Password": "guest",
"VirtualHost": "/",
"MessageOption": {
"MaxRetryCount": 3,
"RetryDelayMilliseconds": 5000,
"MaxOutstandingConfirms": 1000,
"BatchSize": 20
}
}
}
Dependency Injection
// using JfYu.RabbitMQ;
// using Microsoft.Extensions.Configuration;
// using Microsoft.Extensions.DependencyInjection;
services.AddRabbitMQ((factory, options) =>
{
configuration.GetSection("RabbitMQ").Bind(factory);
configuration.GetSection("RabbitMQ:MessageOption").Bind(options);
});
Declare and Bind
// using RabbitMQ.Client;
var mq = serviceProvider.GetRequiredService<IRabbitMQService>();
// Optional: configure DLQ for the queue via arguments
var args = new Dictionary<string, object?>
{
["x-dead-letter-exchange"] = "dlx",
["x-dead-letter-routing-key"] = "orders.dlq"
};
await mq.QueueDeclareAsync(
queueName: "q.orders",
exchangeName: "ex.orders",
exchangeType: ExchangeType.Direct,
routingKey: "orders",
headers: args);
// Bind a DLX queue
await mq.QueueDeclareAsync("q.orders.dlq");
Publish
// Single
await mq.SendAsync("ex.orders", new { Id = 1, Name = "test" }, routingKey: "orders");
// Batch
await mq.SendBatchAsync("ex.orders", new[]
{
new { Id = 2 },
new { Id = 3 }
}, routingKey: "orders");
Consume (async)
using var cts = new CancellationTokenSource();
// Manual acknowledgement mode (default, autoAck=false)
// Messages must be explicitly ACKed by returning true from handler
// Failed messages (return false or exception) trigger retry/DLQ logic
var channel = await mq.ReceiveAsync<string>(
queueName: "q.orders",
func: async msg =>
{
// return true to ACK; false to trigger retry/DLQ
Console.WriteLine($"received: {msg}");
return true;
},
prefetchCount: 10,
autoAck: false, // default: manual acknowledgement with retry
cancellationToken: cts.Token);
// Automatic acknowledgement mode (autoAck=true)
// Messages are ACKed immediately upon delivery regardless of handler result
// No retry logic - use for high-throughput scenarios where message loss is acceptable
var channel2 = await mq.ReceiveAsync<string>(
queueName: "q.logs",
func: async msg =>
{
Console.WriteLine($"received: {msg}");
// return value ignored in auto-ack mode
// exceptions are logged but don't trigger retry
return true;
},
prefetchCount: 10,
autoAck: true, // automatic acknowledgement, no retry
cancellationToken: cts.Token);
// later: cts.Cancel(); // gracefully cancels consumer and disposes channel
Retry and Dead Letter
- Manual Acknowledgement (autoAck=false, default): On failure (handler returns false or throws), the library increments header
x-retry-countand republishes to the original exchange/routing key untilMaxRetryCountis reached. When retries exceedMaxRetryCount, the message is rejected without requeue. Configure your queue withx-dead-letter-exchangeandx-dead-letter-routing-keyto route to a DLQ. - Automatic Acknowledgement (autoAck=true): Messages are acknowledged immediately upon delivery regardless of handler success or exceptions. No retry logic is applied. Use this mode for high-throughput scenarios where message loss is acceptable or when you implement your own retry logic.
Targets
- netstandard2.0, net8.0, net9.0, net10.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Newtonsoft.Json (>= 13.0.4)
- RabbitMQ.Client (>= 7.2.0)
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Newtonsoft.Json (>= 13.0.4)
- RabbitMQ.Client (>= 7.2.0)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Newtonsoft.Json (>= 13.0.4)
- RabbitMQ.Client (>= 7.2.0)
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Newtonsoft.Json (>= 13.0.4)
- RabbitMQ.Client (>= 7.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.