CommonHelpers.RabbitMQ 0.0.1-beta.1

This is a prerelease version of CommonHelpers.RabbitMQ.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package CommonHelpers.RabbitMQ --version 0.0.1-beta.1
                    
NuGet\Install-Package CommonHelpers.RabbitMQ -Version 0.0.1-beta.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="CommonHelpers.RabbitMQ" Version="0.0.1-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CommonHelpers.RabbitMQ" Version="0.0.1-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="CommonHelpers.RabbitMQ" />
                    
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 CommonHelpers.RabbitMQ --version 0.0.1-beta.1
                    
#r "nuget: CommonHelpers.RabbitMQ, 0.0.1-beta.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 CommonHelpers.RabbitMQ@0.0.1-beta.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=CommonHelpers.RabbitMQ&version=0.0.1-beta.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CommonHelpers.RabbitMQ&version=0.0.1-beta.1&prerelease
                    
Install as a Cake Tool

🐰 CommonHelpers.RabbitMQ

Adaptador resiliente de mensageria para RabbitMQ implementando a abstração unificada IEventProducer e IEventHandler<T>, com suporte automático a Publisher Confirms, Dead-Letter Queue (.dlq), retentativas com Polly e injeção de dependência simplificada para .NET 6, .NET 8 e .NET 9.

.NET 6.0 .NET 8.0 .NET 9.0 Version License: MIT


📦 Instalação

Adicione o pacote ao seu projeto via .NET CLI:

dotnet add package CommonHelpers.RabbitMQ --version 0.0.1-beta.1

🚀 Como Usar

1. Configuração no Program.cs

using CommonHelpers.RabbitMQ.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Registra a infraestrutura do RabbitMQ e o IEventProducer agnóstico
builder.Services.AddRabbitMqMessaging(builder.Configuration);

// Registra o consumidor de eventos para um handler específico
builder.Services.AddRabbitMqConsumer<OrderCreatedEvent, OrderCreatedHandler>(
    queueName: "app.orders.created", 
    routingKey: "orders.created");

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

2. Publicando Eventos de Forma Agnóstica (IEventProducer)

Sua camada de aplicação ou domínio depende apenas da interface agnóstica IEventProducer:

using CommonHelpers.Messaging;

public class OrderService
{
    private readonly IEventProducer _producer;

    public OrderService(IEventProducer producer)
    {
        _producer = producer;
    }

    public async Task CreateOrderAsync(OrderDto order, CancellationToken ct)
    {
        var orderEvent = new OrderCreatedEvent(order.Id, order.Total);

        // Publica sem nenhum acoplamento com o RabbitMQ!
        await _producer.PublishAsync(orderEvent, cancellationToken: ct);
    }
}

3. Consumindo Eventos (IEventHandler<T>)

using CommonHelpers.Messaging;
using CommonHelpers.RequestResponse;

public class OrderCreatedHandler : IEventHandler<OrderCreatedEvent>
{
    public async Task<Result> HandleAsync(EventMessage<OrderCreatedEvent> message, CancellationToken ct)
    {
        Console.WriteLine($"Processando pedido {message.Payload.OrderId}, CorrelationId: {message.CorrelationId}");

        // Retornar Result.Success() envia ACK para o RabbitMQ
        // Retornar Result.Failure(...) direciona para a Dead-Letter Queue (.dlq)
        return Result.Success();
    }
}

4. Configuração no appsettings.json

{
  "RabbitMq": {
    "HostName": "localhost",
    "Port": 5672,
    "UserName": "guest",
    "Password": "guest",
    "VirtualHost": "/",
    "ExchangeName": "amq.topic",
    "ExchangeType": "topic",
    "RetryCount": 3,
    "PrefetchCount": 10
  }
}

🏛️ Topologia Automática de Filas e DLQ

Ao registrar um consumidor com AddRabbitMqConsumer:

  1. A exchange principal (ExchangeName) é declarada automaticamente.
  2. A exchange de Dead-Letter (ExchangeName.dlx) e a fila .dlq são declaradas e vinculadas.
  3. A fila principal é criada com argumentos x-dead-letter-exchange apontando para a .dlx. Em caso de erro fatal ou retentativas esgotadas, a mensagem vai automaticamente para a .dlq.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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