ehreader

package
v0.2.1-0...-bdf8d29 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Easy-to-use consumer API on top of EventHorizon client (which is lower-level)

Index

Constants

This section is empty.

Variables

View Source
var (
	SuggestedPollingInterval = 10 * time.Second
)

Functions

func ClientFromConfig

func ClientFromConfig(conf *Config) *ehclient.Client

func ConfigFromEnv

func ConfigFromEnv() (string, error)

func NewInMemSnapshotStore

func NewInMemSnapshotStore() *inMemSnapshotStore

do not use in anything else than testing

func UnsupportedEventTypeErr

func UnsupportedEventTypeErr(e ehevent.Event) error

helper for your code to generate an error

Types

type Config

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

func GetConfig

func GetConfig(getter configGetter) (*Config, error)

func (*Config) ClientDynamoDbOptions

func (c *Config) ClientDynamoDbOptions() ehclient.DynamoDbOptions

func (*Config) SnapshotsDynamoDbOptions

func (c *Config) SnapshotsDynamoDbOptions() ehclient.DynamoDbOptions

type DynamoSnapshotItem

type DynamoSnapshotItem struct {
	Stream  string `json:"s"` // stream + context form the composite key
	Context string `json:"c"` // different software can read the same stream,
	Version int64  `json:"v"` // we conditionally put updates into DynamoDB as not to overwrite advanced state
	Data    []byte `json:"d"` // actual snapshot data
}

type EventProcessorHandler

type EventProcessorHandler func(
	cur ehclient.Cursor,
	handleEvent func(ehevent.Event) error,
	commit func(ehclient.Cursor) error,
) error
encapsulates:

1) validate that current version is what we think it is 2) process events (via callback) 3) commit (via callback), while updating version

type EventsProcessor

type EventsProcessor interface {
	/*	returns error if:

		- failed to start a tx (user code)
		- failed to resolve the version (user code)
		- handle (infra code) failed which itself contains:
		  * error for handleEvent()
		  * commit()
		  * etc.
	*/
	ProcessEvents(ctx context.Context, handle EventProcessorHandler) error
	GetEventTypes() ehevent.Allocators
}

type EventsProcessorSnapshotCapability

type EventsProcessorSnapshotCapability interface {
	InstallSnapshot(*Snapshot) error
	Snapshot() (*Snapshot, error)
}

type EventsProcessorWithSnapshots

type EventsProcessorWithSnapshots interface {
	EventsProcessor
	EventsProcessorSnapshotCapability
}

type Reader

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

Serves reads for one processor. not safe for concurrent use

func New

func New(processor EventsProcessor, client ehclient.Reader, logger *slog.Logger) *Reader

"keep processor happy by feeding it from client"

func NewWithSnapshots

func NewWithSnapshots(
	processor EventsProcessorWithSnapshots,
	client ehclient.Reader,
	snapStore SnapshotStore,
	logger *slog.Logger,
) *Reader

func (*Reader) LoadUntilRealtime

func (r *Reader) LoadUntilRealtime(ctx context.Context) error

func (*Reader) Synchronizer

func (r *Reader) Synchronizer(
	ctx context.Context,
	pollInterval time.Duration,
	logger *slog.Logger,
) error

starts "realtime" sync. until we get pub/sub, we're stuck with polling. but this is the API that will hide better realtime implementation once EventHorizon matures. runs forever (or until ctx is cancelled).

func (*Reader) TransactWrite

func (r *Reader) TransactWrite(ctx context.Context, fn func() error) error

wraps your AppendAfter() result with state-refreshed retries for ErrOptimisticLockingFailed FIXME: currently this cannot be used along with Synchronizer(), because the Reader

is not safe for concurrent use

type Snapshot

type Snapshot struct {
	Cursor ehclient.Cursor
	Data   []byte
}

func NewSnapshot

func NewSnapshot(cursor ehclient.Cursor, data []byte) *Snapshot

type SnapshotStore

type SnapshotStore interface {
	// NOTE: returns os.ErrNotExist if snapshot is not found (which MUST not be
	//       considered an actual error)
	LoadSnapshot(ctx context.Context, cursor ehclient.Cursor) (*Snapshot, error)
	StoreSnapshot(ctx context.Context, snapshot Snapshot) error
}

func NewDynamoDbSnapshotStore

func NewDynamoDbSnapshotStore(opts ehclient.DynamoDbOptions, context string) (SnapshotStore, error)

type Tenant

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

func TenantId

func TenantId(id string) Tenant

func (Tenant) Stream

func (t Tenant) Stream(stream string) string

("/users")

=> "/t-314/users"

type TenantCtx

type TenantCtx struct {
	Tenant
	Client ehclient.ReaderWriter
}

func NewTenantCtx

func NewTenantCtx(tenant Tenant, client ehclient.ReaderWriter) *TenantCtx

func TenantCtxFrom

func TenantCtxFrom(getter configGetter) (*TenantCtx, error)

type TenantCtxWithSnapshots

type TenantCtxWithSnapshots struct {
	Tenant
	Client        ehclient.ReaderWriter
	SnapshotStore SnapshotStore
}

func NewTenantCtxWithSnapshots

func NewTenantCtxWithSnapshots(
	tenant Tenant,
	client ehclient.ReaderWriter,
	snapshotStore SnapshotStore,
) *TenantCtxWithSnapshots

func TenantCtxWithSnapshotsFrom

func TenantCtxWithSnapshotsFrom(
	getter configGetter,
	appContextId string,
) (*TenantCtxWithSnapshots, error)

Directories

Path Synopsis
Test helpers for testing EventHorizon consumers.
Test helpers for testing EventHorizon consumers.

Jump to

Keyboard shortcuts

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