Korjn.AmqpClientInject 9.0.2

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

AmqpClientInject

AmqpClientInject is a lightweight dependency injection wrapper for integrating AMQP-based messaging (such as RabbitMQ, ActiveMQ Artemis) into .NET applications. It simplifies the configuration and usage of AMQP clients using Microsoft.Extensions.DependencyInjection.

Features

  • Seamless integration with .NET Dependency Injection (DI)
  • Simplifies AMQP connection management
  • Supports configuring multiple AMQP clients
  • Compatible with AMQP 1.0 implementations

Installation

The package is available on NuGet (Coming soon). Install it using the following command:

 dotnet add package AmqpClientInject

Getting Started

1. Registering AmqpClientInject in DI

Add the necessary dependencies to your Program.cs or Startup.cs:

Registering a Default AMQP Client
using Microsoft.Extensions.DependencyInjection;
using AmqpClientInject;

var services = new ServiceCollection();

services.AddAmqpClient(options =>
{
    options.Host = "localhost";
    options.Port = 5672;
    options.UserName = "guest";
    options.Password = "guest";
});
Registering Multiple Named AMQP Clients
services.AddAmqpClient("Primary", options =>
{
    options.Host = "primary-host";
    options.Port = 5672;
    options.UserName = "user1";
    options.Password = "password1";
});

services.AddAmqpClient("Secondary", options =>
{
    options.Host = "secondary-host";
    options.Port = 5672;
    options.UserName = "user2";
    options.Password = "password2";
});

services.AddAmqpClient("Secondary", (options, services) =>
{
    options.Host = "secondary-host";
    options.Port = 5672;
    options.UserName = "user2";
    options.Password = "password2";
});

2. Using IAmqpClient

Creating Receiver and Sender
public class AmqpService
{
    private readonly IAmqpClient _amqpClient;

    public AmqpService(IAmqpClient amqpClient)
    {
        _amqpClient = amqpClient;
    }

    public async Task ReceiveMessagesAsync(string receiverName, string address)
    {
        var receiver = await _amqpClient.CreateReceiverAsync(receiverName, address);
        receiver.Start(async (receiver, message) =>
        {
            Console.WriteLine($"Received message: {message.Body}");
            await receiver.AcceptAsync(message);
        });
    }

    public async Task SendMessageAsync(string senderName, string address, string content)
    {
        var sender = await _amqpClient.CreateSenderAsync(senderName, address);
        var message = new Message(content);
        sender.Send(message);
    }
}

3. Using AmqpClientExtensions for Message Sending

public class AmqpMessageService
{
    private readonly IAmqpClient _amqpClient;

    public AmqpMessageService(IAmqpClient amqpClient)
    {
        _amqpClient = amqpClient;
    }

    public async Task SendCustomMessageAsync(string senderName, string address, string correlationId, string content, TimeSpan? delay = null)
    {
        await _amqpClient.SendMessageAsync(senderName, address, correlationId, content, delay);
    }
}

Configuration Options

You can customize connection settings using the ConnectionOptions class:

Option Description Default Value
Host AMQP broker hostname localhost
Port AMQP port 5672
UserName AMQP username guest
Password AMQP password guest
ApplicationName Optional application name null

Example:

services.AddAmqpClient(options =>
{
    options.Host = "amqp.example.com";
    options.Port = 5672;
    options.UserName = "user";
    options.Password = "password";
    options.ApplicationName = "MyApp";
});

Why Use AmqpClientInject?

  • Reduces boilerplate AMQP setup code
  • Ensures best practices for connection management
  • Easily configurable and extendable

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

Contact

For support or inquiries, please open an issue on GitHub.

Product Compatible and additional computed target framework versions.
.NET 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 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 Korjn.AmqpClientInject:

Package Downloads
Korjn.AmqpMessageReceiver

AMQP Message Receiver is a high-performance, fault-tolerant .NET library for receiving and processing AMQP messages asynchronously.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.2 136 5/2/2025
9.0.1 148 4/4/2025
9.0.0 155 3/28/2025