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 ¶
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.
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 ¶
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 ¶
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.