Skip to content

Latest commit

 

History

History
136 lines (94 loc) · 6.16 KB

README.md

File metadata and controls

136 lines (94 loc) · 6.16 KB

Oragon.RabbitMQ

Quality Gate Status Bugs Code Smells Coverage Duplicated Lines (%) Reliability Rating Security Rating Technical Debt Maintainability Rating Vulnerabilities GitHub last commit

Official Release

NuGet Version

Others

GitHub Tag Latest GitHub Tag

GitHub Release Latest GitHub Release

MyGet Version Latest MyGet Package

Tech / Skill

C# .Net Visual Studio

Jenkins

Telegram 🇧🇷

Opinionated and Simplified Minimal APIs for Consuming Messages from RabbitMQ, Ensuring No Crucial Configurations Are Hidden.

What is Oragon.RabbitMQ?

Oragon.RabbitMQ provides everything you need to create resilient RabbitMQ consumers without the need to study numerous books and articles or introduce unknown risks to your environment.

If you have a service like this

public class BusinessService
{
    public async Task DoSomethingAsync(BusinessCommandOrEvent commandOrEvent)
    {
        ... business core ...
    }
}

You will create a RabbitMQ Consumers with this

Singleton

builder.Services.AddSingleton<BusinessService>();

builder.Services.AddSingleton<IAMQPSerializer, SystemTextJsonAMQPSerializer>();

builder.Services.MapQueue<BusinessService, BusinessCommandOrEvent>(config => config
    .WithDispatchInRootScope()    
    .WithAdapter((svc, msg) => svc.DoSomethingAsync(msg))
    .WithQueueName("events")
    .WithPrefetchCount(1)
);

Scoped

builder.Services.AddScoped<BusinessService>();

builder.Services.AddSingleton<IAMQPSerializer, SystemTextJsonAMQPSerializer>();

builder.Services.MapQueue<BusinessService, BusinessCommandOrEvent>(config => config
    .WithDispatchInChildScope()    
    .WithAdapter((svc, msg) => svc.DoSomethingAsync(msg))
    .WithQueueName("events")
    .WithPrefetchCount(1)
);

Scoped and Keyed Services, Same Type, Multiple Consumers, Using NewtonsoftAMQPSerializer

builder.Services.AddKeyedScoped<BusinessService>("key-of-service-1");
builder.Services.AddKeyedScoped("key-of-service-2", (sp, key) => new BusinessService(... custom dependencies ...));

builder.Services.AddSingleton<IAMQPSerializer, NewtonsoftAMQPSerializer>();

builder.Services.MapQueue<BusinessService, BusinessCommandOrEvent>(config => config
    .WithDispatchInChildScope()
    .WithKeyedService("key-of-service-1") 
    .WithAdapter((svc, msg) => svc.DoSomethingAsync(msg))
    .WithQueueName("events1")
    .WithPrefetchCount(1)
);

builder.Services.MapQueue<BusinessService, BusinessCommandOrEvent>(config => config
    .WithDispatchInChildScope()
    .WithKeyedService("key-of-service-2") 
    .WithAdapter((svc, msg) => svc.DoSomethingAsync(msg))
    .WithQueueName("events2")
    .WithPrefetchCount(1)
);

Concepts

Decoupling Business Logic from Infrastructure

This approach is designed to decouple RabbitMQ consumers from business logic, ensuring that business code remains unaware of the queue consumption context.

The result is incredibly simple, decoupled, agnostic, more reusable, and highly testable code.

Opinionated Design: Why?

This consumer is focused on creating a resilient consumer using manual acknowledgments.

  • The flow produces a BasicReject without requeue for serialization failures (e.g., incorrectly formatted messages), you will use dead-lettering to ensure these messages are not lost.
  • The flow produces a BasicNack with requeue for processing failures, allowing for message reprocessing.
  • Minimal API design style made without reflection
  • Extensible with support for custom serializers and encoders

RabbitMQ Tracing com OpenTelemetry

Full support for OpenTelemetry on publishing or consuming RabbitMQ messages.

Refactored to use RabbitMQ.Client 7x (with IChannel instead IModel)