outbox

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package outbox implements SQL transactional event storage and at-least-once Kafka delivery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsertSQL

func InsertSQL(dialect string, r Record) (string, []any, error)

InsertSQL returns bound SQL to execute in the SAME transaction as application state.

Types

type Record

type Record struct {
	ID      string
	Message kafka.Message
}

Record contains persisted processing or event metadata.

func New

func New(m kafka.Message) (Record, error)

New constructs and validates an explicitly owned instance. See package documentation for defaults and cleanup.

type SQLStore

type SQLStore struct {
	DB                     *sql.DB
	Dialect                string
	Producer               kafka.Producer
	BatchSize, MaxAttempts int
	RetryDelay             time.Duration
}

SQLStore uses database row locks and SKIP LOCKED for claims. Run migrations explicitly.

func (SQLStore) Cleanup

func (s SQLStore) Cleanup(ctx context.Context, cutoff time.Time) (int64, error)

Cleanup deletes completed records older than cutoff; failed records require explicit operator disposition.

func (SQLStore) Dispatch

func (s SQLStore) Dispatch(ctx context.Context) (int, error)

Dispatch holds row locks through bounded broker publishing and commits delivery state afterward. A broker acknowledgment followed by a failed SQL commit can deliver duplicates. Event IDs are propagated for deduplication.

Jump to

Keyboard shortcuts

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