Skip to content

[Feature]: Transactional Outbox Pattern Integration #227

@eneshoxha

Description

@eneshoxha

Title: Add transactional outbox behavior for reliable event publishing with Cortex.Streams

Labels: enhancement, mediator, new-package

Body:

Problem

When a command handler persists data and publishes notifications/events, there's a consistency gap: the database commit can succeed but the notification publish can fail (or vice versa). The transactional outbox pattern solves this by writing events to an outbox table within the same database transaction, then a background process relays them to the event bus.

This bridges the gap between Cortex.Mediator (in-process commands) and Cortex.Streams (event streaming).

Proposed Solution

Create a Cortex.Mediator.Outbox package:

  • IOutboxStore interface for persisting outbox messages (with EF Core and Dapper implementations)
  • OutboxCommandBehavior<TCommand, TResult> -- captures notifications published during command handling and writes them to the outbox within the same transaction
  • OutboxRelayService -- IHostedService that polls the outbox and publishes to Cortex.Streams
  • [PublishToOutbox] attribute to opt-in specific notifications

Relationship to Existing Packages

  • Uses Cortex.Mediator.Behaviors.Transactional for transaction management
  • Publishes to Cortex.Streams for event distribution

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfeatureThis label is in use for minor version increments

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions