Documentation
¶
Index ¶
- Variables
- type AfterHook
- type BeforeHook
- type Dispatcher
- type ErrorHook
- type Event
- type EventStore
- 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) Subscribe(ctx context.Context, e Event) error
- func (es *EventStore) Use(mw Middleware)
- type HandlerFunc
- type Middleware
- type OverrunPolicy
- type Result
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) 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) 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 )
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
drop_oldest
command
|
|
|
fasthttp
command
main.go
|
main.go |
|
handler_timeout
command
|
|
|
middleware
command
|
|
|
publisher_timeout
command
|
|
|
return_error
command
|