Documentation
¶
Overview ¶
Package event provides in-memory event bus and publisher implementations. It implements the domain event interfaces for local event handling.
Package event provides in-memory event bus and publisher implementations. It implements the domain event interfaces for local event handling.
Index ¶
- Constants
- Variables
- func NewMemoryEventBus(logger logging.Logger) events.EventBus
- func NewMemoryPublisher(logger logging.Logger) event.Publisher
- type MemoryEventBus
- func (b *MemoryEventBus) Health(_ context.Context) error
- func (b *MemoryEventBus) Publish(ctx context.Context, event events.Event) error
- func (b *MemoryEventBus) PublishBatch(ctx context.Context, eventList []events.Event) error
- func (b *MemoryEventBus) Start(_ context.Context) error
- func (b *MemoryEventBus) Stop(_ context.Context) error
- func (b *MemoryEventBus) Subscribe(_ context.Context, eventName string, ...) error
- func (b *MemoryEventBus) Unsubscribe(_ context.Context, eventName string) error
- type MemoryPublisher
- func (p *MemoryPublisher) ClearEvents()
- func (p *MemoryPublisher) GetEvents() []event.Event
- func (p *MemoryPublisher) Publish(ctx context.Context, evt event.Event) error
- func (p *MemoryPublisher) Subscribe(_ context.Context, eventName string, ...) error
- func (p *MemoryPublisher) WithMaxEvents(maxEvents int) *MemoryPublisher
Constants ¶
const (
// DefaultMaxEvents is the default maximum number of events to store
DefaultMaxEvents = 1000
)
Variables ¶
var ErrInvalidEvent = errors.New("invalid event")
ErrInvalidEvent is returned when an invalid event is published
Functions ¶
func NewMemoryEventBus ¶
NewMemoryEventBus creates a new memory-based event bus
Types ¶
type MemoryEventBus ¶
type MemoryEventBus struct {
// contains filtered or unexported fields
}
MemoryEventBus implements events.EventBus using in-memory storage
func (*MemoryEventBus) Health ¶
func (b *MemoryEventBus) Health(_ context.Context) error
Health returns the health status of the event bus
func (*MemoryEventBus) PublishBatch ¶
PublishBatch publishes multiple events
func (*MemoryEventBus) Start ¶
func (b *MemoryEventBus) Start(_ context.Context) error
Start starts the event bus
func (*MemoryEventBus) Stop ¶
func (b *MemoryEventBus) Stop(_ context.Context) error
Stop stops the event bus
func (*MemoryEventBus) Subscribe ¶
func (b *MemoryEventBus) Subscribe( _ context.Context, eventName string, handler func(context.Context, events.Event) error, ) error
Subscribe subscribes to an event
func (*MemoryEventBus) Unsubscribe ¶
func (b *MemoryEventBus) Unsubscribe(_ context.Context, eventName string) error
Unsubscribe unsubscribes from an event
type MemoryPublisher ¶
type MemoryPublisher struct {
// contains filtered or unexported fields
}
MemoryPublisher is an in-memory implementation of the events.Publisher interface
func (*MemoryPublisher) ClearEvents ¶
func (p *MemoryPublisher) ClearEvents()
ClearEvents clears all published events
func (*MemoryPublisher) GetEvents ¶
func (p *MemoryPublisher) GetEvents() []event.Event
GetEvents returns all published events
func (*MemoryPublisher) Subscribe ¶
func (p *MemoryPublisher) Subscribe( _ context.Context, eventName string, handler func(ctx context.Context, event event.Event) error, ) error
Subscribe adds a handler for a specific event type
func (*MemoryPublisher) WithMaxEvents ¶
func (p *MemoryPublisher) WithMaxEvents(maxEvents int) *MemoryPublisher
WithMaxEvents sets the maximum number of events to store