fileoutbox

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fileoutbox provides a dependency-free JSON Lines outbox adapter for runtime/contracts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder func(json.RawMessage) (any, error)

Decoder converts one persisted JSON payload back into the typed Go event value expected by runtime/contracts subscribers.

type Option

type Option func(*Store)

Option configures a Store.

func WithBatchSize

func WithBatchSize(size int) Option

WithBatchSize sets the maximum number of records returned by one worker batch. Non-positive values keep the default.

func WithDeadLetter

func WithDeadLetter(deadLetterPath string, maxAttempts int) Option

WithDeadLetter moves records to deadLetterPath after maxAttempts failed deliveries. Non-positive maxAttempts or an empty path disables dead-lettering.

func WithDecoder

func WithDecoder(eventType string, decoder Decoder) Option

WithDecoder registers a decoder for one stored event type.

func WithJSONDecoder

func WithJSONDecoder[T any](eventType string) Option

WithJSONDecoder registers a JSON decoder for one stored event type.

func WithJSONTypeDecoder

func WithJSONTypeDecoder[T any]() Option

WithJSONTypeDecoder registers a JSON decoder using the same Go type name stored by runtime/contracts when T is emitted.

type Record

type Record struct {
	ID            string                  `json:"id"`
	StoredAt      time.Time               `json:"storedAt"`
	Category      contracts.EventCategory `json:"category"`
	Type          string                  `json:"type"`
	Value         json.RawMessage         `json:"value"`
	Attempts      int                     `json:"attempts,omitempty"`
	LastAttemptAt *time.Time              `json:"lastAttemptAt,omitempty"`
	LastError     string                  `json:"lastError,omitempty"`
}

Record is one durable outbox row stored as a JSON Lines object.

type Store

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

Store appends event envelopes to a JSON Lines file and can replay them as an EventSource. Ack removes delivered records; Nack records retry metadata and leaves records for later delivery.

func New

func New(path string, options ...Option) *Store

New creates a file-backed outbox at path.

func (*Store) DeadLetterRecords

func (store *Store) DeadLetterRecords(ctx context.Context) ([]Record, error)

DeadLetterRecords returns records moved out of the pending outbox by the configured dead-letter policy.

func (*Store) ReceiveEventBatch

func (store *Store) ReceiveEventBatch(ctx context.Context) (contracts.EventBatch, error)

ReceiveEventBatch returns the next pending records as typed event envelopes. It returns contracts.ErrEventSourceClosed when the outbox is empty.

func (*Store) Records

func (store *Store) Records(ctx context.Context) ([]Record, error)

Records returns all currently pending outbox records.

func (*Store) StoreEvents

func (store *Store) StoreEvents(ctx context.Context, events []contracts.EventEnvelope) error

StoreEvents appends events to the outbox file.

Jump to

Keyboard shortcuts

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