Documentation
¶
Index ¶
- Variables
- type AfterHook
- type BeforeHook
- type Dispatcher
- type ErrorHook
- type Event
- type EventStore
- func (es *EventStore) BeginTransaction() *Transaction
- func (es *EventStore) Close(ctx context.Context) error
- func (es *EventStore) Drain(ctx context.Context) error
- func (es *EventStore) Metrics() (published, processed, errors uint64)
- func (es *EventStore) OnAfter(hook AfterHook)
- func (es *EventStore) OnBefore(hook BeforeHook)
- func (es *EventStore) OnError(hook ErrorHook)
- func (es *EventStore) Publish()
- func (es *EventStore) Schedule(ctx context.Context, t time.Time, e Event) *time.Timer
- func (es *EventStore) ScheduleAfter(ctx context.Context, d time.Duration, e Event) *time.Timer
- func (es *EventStore) Subscribe(ctx context.Context, e Event) error
- func (es *EventStore) Use(mw Middleware)
- type HandlerFunc
- type Middleware
- type OverrunPolicy
- type Result
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ErrBufferFull = errors.New("goeventbus: buffer is full")
ErrBufferFull is returned by Subscribe when OverrunPolicy==ReturnError and the ring buffer is saturated.
Functions ¶
This section is empty.
Types ¶
type BeforeHook ¶ added in v0.1.39
Hook types for before, after, and error events.
type Dispatcher ¶
type Dispatcher map[interface{}]HandlerFunc
Dispatcher maps event projections to handler functions.
type Event ¶
type Event struct {
ID string
Projection interface{}
Args map[string]any
Ctx context.Context // carried context from Subscribe
}
Event is a unit of work to be dispatched.
type EventStore ¶
type EventStore struct {
// Config flags
Async bool
OverrunPolicy OverrunPolicy
// contains filtered or unexported fields
}
EventStore is a high-performance, lock-free ring buffer with middleware and hooks support.
func NewEventStore ¶
func NewEventStore(dispatcher *Dispatcher, bufferSize uint64, policy OverrunPolicy) *EventStore
NewEventStore initializes a new EventStore. It spins up a default worker pool.
func (*EventStore) BeginTransaction ¶ added in v0.1.42
func (es *EventStore) BeginTransaction() *Transaction
BeginTransaction starts a new transaction on the EventStore.
func (*EventStore) Close ¶ added in v0.1.41
func (es *EventStore) Close(ctx context.Context) error
Close drains all pending async events and shuts down the EventStore.
func (*EventStore) Drain ¶ added in v0.1.40
func (es *EventStore) Drain(ctx context.Context) error
Drain waits for all in-flight async handlers to complete, stopping new dispatch.
func (*EventStore) Metrics ¶ added in v0.1.35
func (es *EventStore) Metrics() (published, processed, errors uint64)
Metrics returns snapshot counters.
func (*EventStore) OnAfter ¶ added in v0.1.39
func (es *EventStore) OnAfter(hook AfterHook)
OnAfter registers a hook that runs after each handler invocation (even on error).
func (*EventStore) OnBefore ¶ added in v0.1.39
func (es *EventStore) OnBefore(hook BeforeHook)
OnBefore registers a hook that runs before each handler invocation.
func (*EventStore) OnError ¶ added in v0.1.39
func (es *EventStore) OnError(hook ErrorHook)
OnError registers a hook that runs only when a handler returns an error.
func (*EventStore) Publish ¶
func (es *EventStore) Publish()
Publish processes all pending events, applying middleware and hooks.
func (*EventStore) ScheduleAfter ¶ added in v0.1.46
ScheduleAfter fires e after the given duration d. If d<=0 it falls back to Schedule(now).
func (*EventStore) Subscribe ¶ added in v0.1.30
func (es *EventStore) Subscribe(ctx context.Context, e Event) error
Subscribe enqueues an Event, applying back-pressure according to OverrunPolicy.
func (*EventStore) Use ¶ added in v0.1.39
func (es *EventStore) Use(mw Middleware)
Use adds middleware to the EventStore. It will be applied in the order added.
type HandlerFunc ¶ added in v0.1.39
HandlerFunc is the signature for event handlers and middleware.
type Middleware ¶ added in v0.1.39
type Middleware func(HandlerFunc) HandlerFunc
Middleware wraps a HandlerFunc, returning a new HandlerFunc.
type OverrunPolicy ¶ added in v0.1.38
type OverrunPolicy int
OverrunPolicy defines what happens when the ring buffer is full.
const ( // DropOldest discards the oldest events when the buffer is full. DropOldest OverrunPolicy = iota // Block causes Subscribe to block (respecting ctx) until space is available. Block // ReturnError makes Subscribe fail fast with ErrBufferFull. ReturnError )
type Result ¶ added in v0.1.11
type Result struct {
Message string
}
Result represents the outcome of an event handler.
type Transaction ¶ added in v0.1.42
type Transaction struct {
// contains filtered or unexported fields
}
Transaction encapsulates a set of events to be committed atomically.
func (*Transaction) Commit ¶ added in v0.1.42
func (tx *Transaction) Commit(ctx context.Context) error
Commit enqueues all buffered events and processes them immediately. It returns the first error encountered from Subscribe or handler execution.
func (*Transaction) Publish ¶ added in v0.1.42
func (tx *Transaction) Publish(e Event)
Publish adds an event to the transaction buffer.
func (*Transaction) Rollback ¶ added in v0.1.42
func (tx *Transaction) Rollback()
Rollback clears the local buffer *and* any events that have already been pushed into the storeâs ring-buffer since the transaction began.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
drop_oldest
command
|
|
|
fasthttp
command
main.go
|
main.go |
|
handler_timeout
command
|
|
|
middleware
command
|
|
|
publisher_timeout
command
|
|
|
return_error
command
|