EasyRabbitMQ.Net
2.0.1
dotnet add package EasyRabbitMQ.Net --version 2.0.1
NuGet\Install-Package EasyRabbitMQ.Net -Version 2.0.1
<PackageReference Include="EasyRabbitMQ.Net" Version="2.0.1" />
<PackageVersion Include="EasyRabbitMQ.Net" Version="2.0.1" />
<PackageReference Include="EasyRabbitMQ.Net" />
paket add EasyRabbitMQ.Net --version 2.0.1
#r "nuget: EasyRabbitMQ.Net, 2.0.1"
#:package EasyRabbitMQ.Net@2.0.1
#addin nuget:?package=EasyRabbitMQ.Net&version=2.0.1
#tool nuget:?package=EasyRabbitMQ.Net&version=2.0.1
EasyRabbitMQ.Net
EasyRabbitMQ.Net is a .NET library that simplifies RabbitMQ messaging for producers and consumers. It provides seamless integration with RabbitMQ Client Version 7 and supports modern .NET 8 dependency injection practices.
Features
- Producer and Consumer Support: Simplifies RabbitMQ messaging.
- Dependency Injection Ready: Fully compatible with
.NET 8
DI patterns. - Asynchronous Operations: Supports async RabbitMQ interactions.
- Customizable Factory Methods: For advanced RabbitMQ setup.
- Error Handling: Provides robust error handling and logging.
Installation
Step 1: Install the Package
Install EasyRabbitMQ.Net from NuGet:
dotnet add package EasyRabbitMQ.Net
Or visit the NuGet Package.
Configuration
Step 2: Add RabbitMQ Settings
Define RabbitMQ settings in appsettings.json
:
{
"RabbitMQ": {
"HostName": "localhost",
"UserName": "guest",
"Password": "guest",
"VirtualHost": "/",
"Port": 5672
}
}
Usage
Consumer Application
For consuming messages, update Program.cs
as follows:
Consumer Program.cs
using EasyRabbitMQ.Net.RabbitMQ.Extensions;
using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
// Load RabbitMQ configuration from appsettings.json
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
// Configure RabbitMQ services
builder.Services.AddRabbitMQServices(builder.Configuration);
// Add logging (optional)
builder.Services.AddLogging();
await builder.Build().RunAsync();
Producer Application
For producing messages, update Program.cs
as follows:
Producer Program.cs
using EasyRabbitMQ.Net.RabbitMQ.Extensions;
using Microsoft.Extensions.Hosting;
var builder = Host.CreateApplicationBuilder(args);
// Configure RabbitMQ services
builder.Services.AddRabbitMQServices(builder.Configuration);
// Add logging (optional)
builder.Services.AddLogging();
await builder.Build().RunAsync();
Advanced Usage
Factory Method for Custom Initialization
For advanced RabbitMQ initialization, you can use the RabbitMQFactory class:
using EasyRabbitMQ.Net.RabbitMQ.Models;
using EasyRabbitMQ.Net.Consumer;
var factory = new RabbitMQFactory(configuration, loggerFactory);
var producer = await factory.CreateProducer();
var consumer = await factory.CreateConsumerAsync();
Dependency Injection Extension
You can use the AddRabbitMQServices
extension method to register RabbitMQ services easily. This method registers:
- RabbitMQ configuration (
RabbitMQSettings
) - Producers (
IMessageProducer
) - Consumers (
IMessageConsumer
) - RabbitMQ connection and channel lifecycle management
services.AddRabbitMQServices(configuration);
Sample Projects
Producer Application
This sample demonstrates how to send messages using EasyRabbitMQ.Net
. Refer to the Producer Program.cs above.
Consumer Application
This sample demonstrates how to consume messages using EasyRabbitMQ.Net
. Refer to the Consumer Program.cs above.
Changelog
Version 2.0.0
- Updated to RabbitMQ Client Version 7.
- Support for .NET 8 hosting and dependency injection.
- Enhanced consumer and producer functionality.
- Simplified RabbitMQ configuration and setup.
Contributing
Contributions are welcome! Visit the GitHub repository for more information on how to contribute.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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.Configuration (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.0)
- Microsoft.Extensions.Hosting (>= 9.0.0)
- Microsoft.Extensions.Logging (>= 9.0.0)
- Newtonsoft.Json (>= 13.0.3)
- RabbitMQ.Client (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Enhanced error handling on the consumer side.