Korjn.AmqpMessageReceiver 9.0.0

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

AmqpMessageReceiver

AmqpMessageReceiver is a .NET library for receiving messages from AMQP brokers (such as RabbitMQ, ActiveMQ Artemis). It is designed for seamless integration into .NET applications using Dependency Injection (DI).

Features

  • Easy integration with .NET Dependency Injection (DI)
  • Support for AMQP-based brokers (RabbitMQ, ActiveMQ Artemis, etc.)
  • Configurable message handling with IMessageReceiver
  • Customizable options via MessageReceiverOptions

Installation

Install the package via NuGet:

dotnet add package AmqpClientInject
dotnet add package AmqpMessageReceiver

Or via the NuGet Package Manager:

Install-Package AmqpMessageReceiver

Configuration and Registration

To use AmqpMessageReceiver, you need to register it in your DI container with the required configuration.

Registering the Receiver in DI

In your Program.cs or Startup.cs, register the receiver:

using AmqpMessageReceiver;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHostedService<Worker>();
services.AddAmqpClient(options =>
{
    options.Host = "localhost";
    options.Port = 5672;
    options.UserName = "guest";
    options.Password = "guest";
});
builder.Services.AddMessageReceiver(options =>
{
    options.Address = "my-queue";
    options.ReceiverName = "my-Receiver";
    options.MaxConcurrency = 10;
});

var app = builder.Build();
app.Run();

Implementing a Message Receiver in a Worker Service

Create a Worker service that processes messages using IMessageReceiver and IAmqpClient:

using AmqpMessageReceiver;
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;

public class Worker(IAmqpClient amqpClient, IMessageReceiver receiver) : BackgroundService
{
    private async Task ProcessMessageAsync(MessageContext context)
    {        
        try
        {
            // Process the message
            context.Acknowledge(true);             
        }
        catch (Exception e)
        {
            context.Acknowledge(false);
        }
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {     
        await receiver.ExecuteAsync(amqpClient, ProcessMessageAsync, stoppingToken);        
    }    
}

Contribution & Support

If you have any questions or suggestions, feel free to create an issue or a pull request in the GitHub repository.

License

This library is distributed under the MIT license.

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

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
9.0.0 174 4/1/2025