consumerhook

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package consumerhook lets package consumer hand a Reactor and a Projection what they need from a Runtime and its runner without exporting it.

consumer registers its hooks at init time. reactor and projection import consumer, so the hooks are always registered before they are used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPermanent

func IsPermanent(err error) bool

IsPermanent reports whether err is marked consumer.Permanent.

func ReactorOption

func ReactorOption(o ReactorOptions) any

ReactorOption returns a consumer.Option applying o. It is typed any because this package cannot import consumer; the caller asserts it.

func Register

func Register(h Hooks)

Register installs the hooks. Only package consumer calls it.

func Reset

func Reset(ctx context.Context, in ResetInput) error

Reset runs Hooks.Reset.

Types

type Backend

type Backend struct {
	Codec *eventstore.Codec
	// Pool and Schema are set for a PgRuntime; Pool is nil in memory.
	Pool   *pgxpool.Pool
	Schema string
}

Backend is the event log behind a consumer Runtime.

func RuntimeBackend

func RuntimeBackend(rt any) (Backend, bool)

RuntimeBackend returns the Backend of a consumer Runtime, or false when rt is none.

type Changes

type Changes interface {
	// Publish sends payload when the transaction in ctx commits, or at once
	// outside one.
	Publish(ctx context.Context, payload string) error
	// Subscribe returns a Feed of every payload published from now on.
	Subscribe() (Feed, error)
}

Changes sends and delivers the change payloads of one Runtime, for package projection.

func RuntimeChanges

func RuntimeChanges(rt any) (Changes, bool)

RuntimeChanges returns the change channel of a consumer Runtime, or false when rt is none.

type DecodeFailedFunc

type DecodeFailedFunc func(ctx context.Context, f DecodeFailure) error

DecodeFailedFunc receives an event whose payload does not decode, in place of the Consumer going Stopped. ctx carries the event's Tenant and Correlation. A returned error is retried like a handler error.

type DecodeFailure

type DecodeFailure struct {
	// Env is the event without its decoded Event.
	Env     eventstore.Envelope
	Payload eventstore.Payload
	// Err is the decode error, marked consumer.Permanent.
	Err error
}

DecodeFailure is an event whose payload does not decode.

type Feed

type Feed interface {
	C() <-chan notify.Notification
	Close()
}

Feed delivers change payloads. *notify.Subscription is one.

type Hooks

type Hooks struct {
	// Changes returns the change channel of a consumer Runtime, or false
	// when rt is none.
	Changes func(rt any) (Changes, bool)
	// Reset takes the leases of in.Consumers and runs in.Clear and the
	// rewind of their Cursors to the start of the log in one Cursor
	// transaction. It fails with consumer.ErrRunning while one of them runs.
	Reset func(ctx context.Context, in ResetInput) error
	// Backend returns the Backend of a consumer Runtime, or false when rt is
	// none.
	Backend func(rt any) (Backend, bool)
	// ReactorOption returns a consumer.Option applying o.
	ReactorOption func(o ReactorOptions) any
	// IsPermanent reports whether err is marked consumer.Permanent.
	IsPermanent func(err error) bool
}

Hooks are the lookups package consumer registers.

type ReactorOptions

type ReactorOptions struct {
	// SeedAtHead seeds a new Cursor at the head of the log when the
	// Consumer first claims it, so history is skipped.
	SeedAtHead bool
	// DecodeFailed, when set, receives undecodable events.
	DecodeFailed DecodeFailedFunc
	// Leased, when set, is called by Run each time it takes the lease, with
	// the lease ctx. Run calls the returned stop when the lease ends.
	Leased func(ctx context.Context) (stop func())
	// Drained, when set, is called by Drain once it has processed up to the
	// head, still under the lease. Its error fails the Drain.
	Drained func(ctx context.Context) error
}

ReactorOptions are the runner behaviours only a Reactor turns on.

type ResetInput

type ResetInput struct {
	// Consumers are *consumer.Consumer values of one Runtime.
	Consumers []any
	// Clear empties the read model inside the reset transaction.
	Clear func(ctx context.Context) error
}

ResetInput names the Consumers to reset and the read model to clear.

Jump to

Keyboard shortcuts

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