EasyRabbitMQ.Net 2.0.1

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

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 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

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.1 148 12/1/2024
2.0.0 115 12/1/2024
1.0.1 98 7/29/2024
1.0.0 93 7/23/2024

- Enhanced error handling on the consumer side.