Documentation
¶
Overview ¶
Easy-to-use consumer API on top of EventHorizon client (which is lower-level)
Index ¶
- Variables
- func ClientFromConfig(conf *Config) *ehclient.Client
- func ConfigFromEnv() (string, error)
- func NewInMemSnapshotStore() *inMemSnapshotStore
- func UnsupportedEventTypeErr(e ehevent.Event) error
- type Config
- type DynamoSnapshotItem
- type EventProcessorHandler
- type EventsProcessor
- type EventsProcessorSnapshotCapability
- type EventsProcessorWithSnapshots
- type Reader
- type Snapshot
- type SnapshotStore
- type Tenant
- type TenantCtx
- type TenantCtxWithSnapshots
Constants ¶
This section is empty.
Variables ¶
var (
SuggestedPollingInterval = 10 * time.Second
)
Functions ¶
func ClientFromConfig ¶
func ConfigFromEnv ¶
func NewInMemSnapshotStore ¶
func NewInMemSnapshotStore() *inMemSnapshotStore
do not use in anything else than testing
func UnsupportedEventTypeErr ¶
helper for your code to generate an error
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
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 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 NewWithSnapshots ¶
func NewWithSnapshots( processor EventsProcessorWithSnapshots, client ehclient.Reader, snapStore SnapshotStore, logger *slog.Logger, ) *Reader
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 ¶
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 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 TenantCtx ¶
type TenantCtx struct {
Tenant
Client ehclient.ReaderWriter
}
func NewTenantCtx ¶
func NewTenantCtx(tenant Tenant, client ehclient.ReaderWriter) *TenantCtx
func TenantCtxFrom ¶
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. |