Gerenciador de filas para o WhiterMediator.
$ dotnet add package WaiterMediator.Extensions.QueuesFila de Domain Events baseada em System.Threading.Channels integrada ao WaiterMediator. Objetivo: enfileirar INotification para processamento em background por um worker que publica eventos via IWaiter.
DomainEventQueue
DomainEventWorker
AddDomainEventQueue (extensão de DI)
Via dotnet CLI:
dotnet add package WaiterMediator.Extensions.Queues
Exemplo mínimo de registro:
// Program.cs
builder.Services.AddWaiter(typeof(Program).Assembly);
builder.Services.AddDomainEventQueue();
Evento:
public record UserCreatedEvent(int UserId) : INotification;
Handler síncrono:
public class UserCreatedHandler : INotificationHandler<UserCreatedEvent>
{
public Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
{
Console.WriteLine($"UserCreated: {notification.UserId}");
return Task.CompletedTask;
}
}
Handler assíncrono:
public class UserCreatedAsyncHandler : INotificationHandler<UserCreatedEvent>
{
public async Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
{
await Task.Delay(100, cancellationToken);
Console.WriteLine($"Processed async: {notification.UserId}");
}
}
// produtor: enfileira um domain event
await domainEventQueue.EnqueueAsync(new UserCreatedEvent(42));
Observação: o DomainEventWorker consome a fila e chama IWaiter.Publish(notification, ct), que resolve e executa os handlers registrados.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
return Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddWaiter(typeof(Program).Assembly);
services.AddDomainEventQueue();
// registrar demais serviços
})
.RunConsoleAsync();
DomainEventQueue
DomainEventWorker
AddDomainEventQueue()
Fluxo recomendado: