LiteBus
CatalogDispatch

Outbox In-Process Event Dispatch

  • ID: dispatch.outbox.in-process
  • Name: Outbox in-process event dispatch
  • Maturity: GA
  • Summary: Deserialize leased outbox envelopes and publish them through IEventMediator.PublishAsync in the same process.

What It Does

EventOutboxDispatcher implements IOutboxDispatcher. It resolves the contract, unprotects and deserializes the payload, builds EventMediationSettings with trace metadata, and publishes via IEventMediator. Types implementing IEvent use the non-generic publish overload; POCO events use a cached closed-generic delegate per event type.

Use this path when integration events should fan out to local handlers only (same service or same process) while still benefiting from durable enqueue and at-least-once processor semantics.

Packages

PackageRole
LiteBus.Outbox.Dispatch.InProcessDispatcher and registration
LiteBus.Events.AbstractionsIEvent, IEventMediator
LiteBus.Outbox.AbstractionsIOutboxDispatcher, envelopes

Requires

  • durable-core.outbox
  • mediator.events (AddEvents)
  • runtime.contract-registry
  • dispatch.registration

Invariants

  • Event types must be registered with Contracts.Register and have handlers when using POCO events.
  • Dispatch wraps non-LiteBusDispatchException failures in LiteBusDispatchException with contract context.
  • Default hook failure policy is DeadLetter (stricter than transport outbox dispatch).
  • At-least-once local publication: handlers must tolerate duplicate event delivery.

Non-Goals

  • Does not publish to external brokers.
  • Does not guarantee cross-process delivery.
  • Does not invoke command handlers.

Public Surface

services.AddLiteBus(litebus =>
{
    litebus.AddEvents(events => { /* handlers */ });
    litebus.AddOutbox(outbox =>
    {
        outbox.EnableOutboxProcessor();
        outbox.UseInProcessDispatch();
    });
});

OutboxModuleBuilder.UseInProcessDispatch()

PackageLiteBus.Outbox.Dispatch.InProcess
RegistersEventOutboxDispatchModule to EventOutboxDispatcher

EventOutboxDispatcher.DispatchAsync(OutboxEnvelope, CancellationToken)

PackageLiteBus.Outbox.Dispatch.InProcess
FlowResolve contract to unprotect to deserialize to build EventMediationSettings to publish
IEvent pathIEventMediator.PublishAsync(IEvent, settings, token)
POCO pathCached closed-generic PublishAsync<TEvent> delegate per contract type
ErrorsRethrows LiteBusDispatchException; wraps other exceptions with contract context

Optional constructor dependency: IOutboxPayloadProtector.

EventOutboxDispatchModule.Build(IModuleConfiguration)

Registers IOutboxDispatcher to EventOutboxDispatcher. Default hook failure policy remains processor default (DeadLetter), not transport outbox CompleteDespiteHookFailure.

Observability

SignalWhen
litebus.outbox.processor.dispatch_durationProcessor histogram around DispatchAsync
litebus.outbox.processor.published / failed / dead_letteredTerminal outcomes after dispatch and hooks
Event pipeline tracingFollows mediator/event handler instrumentation when configured; no outbox-dispatch-specific activity source
No transport send spanIn-process path does not touch the transport layer

Register outbox processor metrics through AddLiteBusOutboxMetrics().

Analyzers

  • LB1007 / LB1017: Contract registration for published event types.
  • LB1014: Processor without dispatcher.

Deep Docs

Test Coverage

Covered

Test methodProject
ProcessPendingAsync_ShouldPublishThroughInProcessOutboxDispatcherAndMarkPublishedLiteBus.Outbox.UnitTests (Dispatch/InProcess/)
InProcessOutboxDispatcher_ShouldPublishPocoEventLiteBus.Outbox.UnitTests (Dispatch/InProcess/)
InProcessOutboxDispatcher_ShouldCopyTraceMetadataIntoMediationSettingsLiteBus.Outbox.UnitTests (Dispatch/InProcess/)
ProcessPendingAsync_ShouldPublishEventThroughPostgreSqlStoreLiteBus.Storage.IntegrationTests (PostgreSql/)
ProcessPendingAsync_WhenDispatcherFails_ShouldMarkFailedWithVisibleAfterLiteBus.Storage.IntegrationTests (PostgreSql/)
PipelinedProcessor_when_after_dispatch_hook_fails_should_persist_dead_letter_without_publishedLiteBus.Outbox.UnitTests
AddOutboxInProcessDispatcher_ShouldRegisterInProcessOutboxDispatcherLiteBus.Outbox.UnitTests (Dispatch/InProcess/)
AddOutboxInProcessDispatcher_WhenCalledTwice_ShouldThrowLiteBus.Outbox.UnitTests (Dispatch/InProcess/)
AddOutboxInProcessDispatcher_WhenAnotherDispatcherRegistered_ShouldThrowLiteBus.Outbox.UnitTests (Dispatch/InProcess/)

Untested

  • Explicit assertion for non-LiteBus failure wrapping into LiteBusDispatchException.
  • EF Core outbox adapter end-to-end coverage in dispatch suites.

Out-of-Scope

  • Publishing to external brokers
  • Cross-process event delivery guarantees
  • Invoking command handlers from outbox dispatch

On this page