outbox

command
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 8 Imported by: 0

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: drel.NewRelay claims a batch under a lease, publishes it, and stamps processed_at. A second poll returns nothing. The lease lets more than one replica poll one table, and partition_key keeps the events of one order in order.

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 .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL