Class Outbox

java.lang.Object
com.babelqueue.outbox.Outbox

public final class Outbox extends Object
The write side of the transactional outbox (ADR-0029): turn a BabelQueue Envelope into a stored outbox row, so the message is persisted atomically with the business data and a separate OutboxRelay publishes it later.

Usage — the caller owns the transaction boundary (this is the whole point):


 connection.setAutoCommit(false);
 try {
     insertOrder(connection, order);                 // the business write
     Envelope env = EnvelopeCodec.make("urn:babel:orders:created", data, "orders", null);
     outbox.write(env);                              // same connection, same tx
     connection.commit();                            // both, or neither
 } catch (Exception e) {
     connection.rollback();
     throw e;
 }
 

Because both writes share one transaction, a crash can never leave the business row committed without its message (the classic dual-write bug) — they commit or roll back together. The handoff to the broker becomes a local problem the relay solves.

This helper is intentionally tiny and dependency-free: it only encodes via the frozen EnvelopeCodec (GR-1 — the envelope bytes are stored unchanged; the outbox never adds an envelope field) and delegates persistence to the injected OutboxStore, which the caller binds to their own DB (GR-7). It does not begin or commit anything.