ITLab.Template.DevPack.Messaging
Provides outcome contracts for message handlers integrated with external brokers (Azure Service Bus and similar). Independent of the in-process CQRS area in Mediator/ — this namespace is exclusively about broker-side settlement (complete, abandon, dead-letter).
Componentes
| Tipo | Nome | Responsabilidade |
|---|---|---|
| Enum | EMessageDisposition | Settlement disposition for a processed broker message: Complete, Abandon, DeadLetter |
| Record | MessageHandlingResult | Outcome of processing a single broker message, carrying disposition, optional Error, transient flag and retry delay |
| Static Class | MessagingErrors | Catalog of well-known errors produced by the messaging infrastructure layer (InvalidPayload, ProcessingFailed) |
Como usar
public async Task<MessageHandlingResult> HandleAsync(OrderShippedMessage msg, CancellationToken ct)
{
if (!msg.IsValid())
{
return MessageHandlingResult.DeadLettered(MessagingErrors.InvalidPayload(msg.RawPayload));
}
try
{
await _handler.ProcessAsync(msg, ct);
return MessageHandlingResult.Completed();
}
catch (TransientServiceUnavailableException ex)
{
return MessageHandlingResult.Abandoned(
MessagingErrors.ProcessingFailed(ex.Message),
isTransient: true,
retryDelay: TimeSpan.FromSeconds(30));
}
}
O que não fazer
- Do not use this namespace for in-process CQRS commands or queries — those live in
Mediator/. - Do not invent custom dispositions outside
EMessageDisposition— broker semantics are fixed. - Do not retry forever inside a handler — use
MessageHandlingResult.Abandoned(..., retryDelay: ...)and let the broker honor its own redelivery policy.
Extensão pelo produto
- Products implement broker-specific adapters that translate
MessageHandlingResultinto the broker's settlement API (e.g.,ServiceBusMessageActions.CompleteMessageAsync). - Products extend the error catalog with product-specific failures, following the
Infrastructure.Messaging.{Code}prefix convention.