Documentation
¶
Overview ¶
Package config holds the outbox runtime settings, the functional options that build them, and the declarative Config struct (mapstructure/validate/default tags) for loading from files or environment.
Index ¶
- Variables
- func ValidSchema(s string) bool
- type Config
- type Option
- func WithBatchSize(n int) Option
- func WithCleanupInterval(d time.Duration) Option
- func WithCodec(c port.Codec) Option
- func WithConcurrency(n int) Option
- func WithConfig(c Config) Option
- func WithHooks(h port.Hooks) Option
- func WithInstanceID(id string) Option
- func WithLeaseDuration(d time.Duration) Option
- func WithListenPool(p *pgxpool.Pool) Option
- func WithLogger(l *slog.Logger) Option
- func WithMaxAttempts(n int) Option
- func WithOrdered(v bool) Option
- func WithPollInterval(d time.Duration) Option
- func WithRetention(ttl time.Duration) Option
- func WithRetryBackoff(b backoff.Backoff) Option
- func WithSchema(schema string) Option
- func WithoutNotify() Option
- type Settings
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSchema = errors.New("outbox: invalid schema identifier")
ErrInvalidSchema is returned when the schema is not a valid identifier.
Functions ¶
func ValidSchema ¶
ValidSchema reports whether s is a safe schema identifier.
Types ¶
type Config ¶
type Config struct {
Schema string `mapstructure:"schema" default:"public"`
PollInterval time.Duration `mapstructure:"poll_interval" default:"1s"`
BatchSize int `mapstructure:"batch_size" default:"100"`
LeaseDuration time.Duration `mapstructure:"lease_duration" default:"30s"`
Concurrency int `mapstructure:"concurrency" default:"1"`
MaxAttempts int `mapstructure:"max_attempts" default:"10"`
Retention time.Duration `mapstructure:"retention"`
CleanupInterval time.Duration `mapstructure:"cleanup_interval"`
Ordered bool `mapstructure:"ordered"`
// DisableNotify turns LISTEN/NOTIFY off (poll-only). The zero value keeps
// NOTIFY enabled, so a hand-built Config does not silently disable it.
DisableNotify bool `mapstructure:"disable_notify"`
}
Config is the declarative outbox configuration, loaded from a file or environment (mapstructure) with validation and defaults. It mirrors the functional options; the logger is injected separately via WithLogger because it is a runtime dependency, not configuration data.
type Option ¶
type Option func(*Settings)
Option configures Settings.
func WithBatchSize ¶
WithBatchSize sets the max rows claimed per cycle (default 100).
func WithCleanupInterval ¶
WithCleanupInterval sets how often the cleaner runs (default off).
func WithConcurrency ¶
WithConcurrency sets the number of relay worker goroutines (default 1).
func WithConfig ¶
WithConfig applies a declarative Config onto the settings. Apply it before any narrower Option you want to win.
func WithInstanceID ¶
WithInstanceID sets the lease owner id (locked_by). Required before Run. Must be unique and stable per process (e.g. the Kubernetes pod name).
func WithLeaseDuration ¶
WithLeaseDuration sets how long a claimed row stays locked (default 30s).
func WithListenPool ¶
WithListenPool supplies the *pgxpool.Pool used for LISTEN/NOTIFY wake-ups. Without it (and unless the relay executor is itself a *pgxpool.Pool), the relay falls back to polling only.
func WithLogger ¶
WithLogger injects the slog logger from outside (default a no-op logger that discards everything).
func WithMaxAttempts ¶
WithMaxAttempts sets the default attempt ceiling before dead-lettering (default 10).
func WithOrdered ¶
WithOrdered enables strict per-partition_key ordering.
func WithPollInterval ¶
WithPollInterval sets how often the relay polls when idle (default 1s).
func WithRetention ¶
WithRetention enables cleanup of published rows older than ttl. The cleaner also needs WithCleanupInterval to run.
func WithRetryBackoff ¶
WithRetryBackoff overrides the retry backoff (default backoff.Default).
func WithSchema ¶
WithSchema sets the Postgres schema the table lives in (default "public").
func WithoutNotify ¶
func WithoutNotify() Option
WithoutNotify disables LISTEN/NOTIFY wake-ups (poll-only).
type Settings ¶
type Settings struct {
InstanceID string
Schema string
PollInterval time.Duration
BatchSize int
LeaseDuration time.Duration
Concurrency int
MaxAttempts int
Backoff backoff.Backoff
Retention time.Duration
CleanupInterval time.Duration
Ordered bool
Notify bool
ListenPool *pgxpool.Pool
Hooks port.Hooks
Codec port.Codec
Logger *slog.Logger
}
Settings is the resolved runtime configuration the engine reads. Build it with Default plus Options, or from a declarative Config via WithConfig.