Documentation
¶
Overview ¶
Example: outbox
Demonstrates the transactional outbox pattern with drel.Engine.UseOutbox. Domain events recorded during a business transaction are written to an outbox table *in the same transaction* as the data changes that produced them. This gives a reliable, exactly-once hand-off to external systems (a CDC pipeline like Debezium, a message bus, or a polling relay) without dual-write races: either the order AND its event commit together, or neither does.
Key concepts shown:
- UseOutbox: register an outbox table; every SaveChanges persists the pending domain events into it within the same transaction.
- Atomicity: when a transaction rolls back, no outbox row is left behind — you never publish an event for work that didn't commit.
- Relay: a polling worker reads unprocessed rows, "publishes" them, and stamps processed_at. A second poll returns nothing — exactly-once.
Runs against in-memory SQLite (pure-Go modernc.org/sqlite, no CGO and no external database needed).
Usage:
cd examples/outbox go run ../../cmd/drel generate # generates orders/order_drel.go + db/drel_gen.go go run .
Click to show internal directories.
Click to hide internal directories.