outbox

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package outbox implements the transactional outbox pattern (ADR-016 §Class 2). Events are written inside the caller's transaction so a business-write rollback atomically prevents the event from being enqueued — no two-phase commit needed.

The table lives in the shared public schema (same as public.tenants) so one pool serves all tenants. The worker (future session) polls with SELECT … FOR UPDATE SKIP LOCKED and processes rows per topic.

Index

Constants

View Source
const NotifyChannel = "outbox_notify"

NotifyChannel is the Postgres LISTEN/NOTIFY channel the engine signals after a successful Enqueue and that the worker (cmd/appximo-worker) LISTENs on. The NOTIFY is only a wake-up HINT: the worker still polls public.outbox, which is the durable source of truth, because a notification emitted while the worker is down is lost forever (NOTIFY is ephemeral, not queued). Keep this constant the single source of truth shared by engine and worker so the two never drift.

Variables

This section is empty.

Functions

func Enqueue

func Enqueue(ctx context.Context, tx pgx.Tx, tenantID, topic string, payload any) (int64, error)

Enqueue inserts an event into public.outbox within tx. Because the INSERT runs inside the caller's transaction, a rollback also rolls back the enqueue — the event never reaches the worker unless the business write commits. Returns the generated row id on success.

func EnsureTable

func EnsureTable(ctx context.Context, pool *pgxpool.Pool) error

EnsureTable creates public.outbox idempotently. Safe to call at every boot.

Types

This section is empty.

Jump to

Keyboard shortcuts

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