Transactional Outbox
The transactional outbox pattern guarantees that events are published to a message broker if and only if the database transaction that triggered them commits. RCommon provides outbox integration for both MassTransit and Wolverine.
The problem the outbox solves
Without an outbox, there is a window between committing a database change and publishing an event where a crash can cause the event to be lost. Conversely, publishing an event before committing risks publishing for a transaction that is later rolled back. The outbox eliminates both failure modes by writing the event to the same database transaction as the business data, then relaying it to the broker after the transaction commits.
Two ways to get an outbox
There are two supported strategies, both fully documented with diagrams in the Event Handling Recipes guide:
- Recipe 2a — broker as producer behind the RCommon outbox. RCommon's own per-datastore outbox stages the row atomically; a post-commit poller relays it to the broker. Works for both MassTransit and Wolverine.
- Recipe 2b — broker-native outbox (MassTransit only). MassTransit's EF Core outbox stages the message; RCommon coordinates the transaction. Wolverine does not support this.
MassTransit — broker-native outbox (Recipe 2b)
dotnet add package RCommon.MassTransit.Outbox