relay

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package relay publishes claimed outbox envelopes with bounded concurrency.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStoreRequired     = errors.New("outbox/relay: store is required")
	ErrPublisherRequired = errors.New("outbox/relay: publisher is required")
	ErrPublisherPanic    = errors.New("outbox/relay: publisher panicked")
	ErrOwnerRequired     = errors.New("outbox/relay: owner is required")
	ErrInvalidConfig     = errors.New("outbox/relay: configuration values must be positive")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Owner                string
	BatchSize            int
	Workers              int
	LeaseDuration        time.Duration
	LeaseRenewalInterval time.Duration
	MaxAttempts          int
	PollInterval         time.Duration
	TransitionTimeout    time.Duration
	Clock                func() time.Time
	Backoff              func(attempt int) time.Duration
	ClassifyError        func(error) ErrorClass
	Wait                 func(context.Context, time.Duration) error
	Serialization        postgres.SerializationMode
	Observer             outbox.Observer
	Logger               *slog.Logger
	Heartbeat            func(context.Context, time.Duration, func(context.Context) error) error
}

Config bounds one relay instance and injects deterministic policy seams.

type ErrorClass

type ErrorClass uint8

ErrorClass controls whether a failed publication is retried or terminated.

const (
	ErrorTransient ErrorClass = iota
	ErrorPermanent
)

type Publisher

type Publisher interface {
	Publish(context.Context, outbox.Envelope) error
}

Publisher accepts an envelope. Returning nil means the publisher accepted it, not that exactly-once delivery has been achieved.

type Relay

type Relay struct {
	// contains filtered or unexported fields
}

Relay coordinates claims, publisher calls, and state transitions.

func New

func New(store Store, publisher Publisher, config Config) (*Relay, error)

New validates and constructs a relay.

func (*Relay) Readiness

func (relay *Relay) Readiness(ctx context.Context) error

Readiness verifies database connectivity and, when supported, publisher connectivity. All failed checks are returned together.

func (*Relay) Run

func (relay *Relay) Run(ctx context.Context) error

Run polls until cancellation. Full batches are followed immediately to drain backlog; partial batches wait through the injected polling function.

func (*Relay) RunOnce

func (relay *Relay) RunOnce(ctx context.Context) (Result, error)

RunOnce claims at most one batch and drains it with bounded worker concurrency. Publisher failures that are durably scheduled are reflected in Result; persistence failures are returned.

type Result

type Result struct {
	Claimed      int
	Published    int
	Delivered    int
	Retried      int
	DeadLettered int
	Released     int
}

Result summarizes one bounded polling cycle.

type Store

Store is the lease-safe persistence contract used by Relay.

Jump to

Keyboard shortcuts

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