Interface IOutboxWriter
Stages outbound messages for reliable delivery via the outbox pattern.
public interface IOutboxWriter
- Extension Methods
Remarks
Inject this interface into handlers to stage outbound messages. The consistency guarantee (eventually-consistent vs. transactional) is determined by configuration, not by which API you call.
Eventually-consistent mode: Messages are buffered during handler execution and staged in the outbox after the handler and its transaction complete. If the process crashes between transaction commit and outbox staging, messages may be lost.
Transactional mode: Messages are written to the outbox store within the ambient transaction, guaranteeing atomicity with the business state change.
Methods
WriteAsync(IDispatchMessage, string?, CancellationToken)
Writes a message to the outbox for reliable delivery.
[RequiresUnreferencedCode("Outbox stores serialize the message payload reflectively; supply JsonSerializerOptions with a source-generated resolver for trimming and AOT.")]
[RequiresDynamicCode("Outbox stores serialize the message payload reflectively; supply JsonSerializerOptions with a source-generated resolver for trimming and AOT.")]
ValueTask WriteAsync(IDispatchMessage message, string? destination, CancellationToken cancellationToken)
Parameters
messageIDispatchMessageThe message to stage.
destinationstringOptional destination/topic for the message.
cancellationTokenCancellationTokenToken to monitor for cancellation.
Returns
- ValueTask
A task representing the write operation.
Exceptions
- ArgumentNullException
Thrown when
messageis null.- InvalidOperationException
Thrown in transactional mode when no ambient transaction is available.