Skip to main content
Table of Contents

Interface ICommandOutboxDispatcher

Namespace
Stratara.Abstractions.Outbox
Assembly
Stratara.Abstractions.dll

Enqueues commands for asynchronous out-of-process execution by the command-handling worker. Implementations first try direct publish (fast path) and fall back to the outbox table if the bus is unreachable.

public interface ICommandOutboxDispatcher
Extension Methods

Examples

Dispatch a fire-and-forget mutation from an API endpoint:

public sealed record PlaceOrder(Guid OrderId, Guid CustomerId, decimal Amount) : ICommand;

app.MapPost("/orders", async (PlaceOrder command, ICommandOutboxDispatcher dispatcher, CancellationToken ct) =>
{
    var envelopeId = await dispatcher.EnqueueCommandAsync(command, ct);
    return Results.Accepted($"/orders/{command.OrderId}", new { envelopeId });
});

Methods

EnqueueCommandAsync<T>(T, CancellationToken)

Enqueue command for asynchronous dispatch.

Task<Guid> EnqueueCommandAsync<T>(T command, CancellationToken cancellationToken = default) where T : ICommand

Parameters

command T

The command to dispatch.

cancellationToken CancellationToken

Propagated to the bus / outbox write.

Returns

Task<Guid>

The id assigned to the envelope.

Type Parameters

T

The concrete command type.

Exceptions

SessionRequiredException

No session context is set on the current scope.

ArgumentException

command implements INamesDataOwner and names an empty tenant or an empty user as the owner of its protected fields. Nothing is stored or published.

EnqueueOutboxEntriesAsync(IEnumerable<OutboxEntry>, CancellationToken)

Drain previously-persisted outboxEntries by attempting to publish each one and deleting on success. Used by the outbox worker.

Task EnqueueOutboxEntriesAsync(IEnumerable<OutboxEntry> outboxEntries, CancellationToken cancellationToken = default)

Parameters

outboxEntries IEnumerable<OutboxEntry>
cancellationToken CancellationToken

Returns

Task