event

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 8 Imported by: 0

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

View Source
const (
	// DefaultMaxEvents is the default maximum number of events to store
	DefaultMaxEvents = 1000
)

Variables

View Source
var ErrInvalidEvent = errors.New("invalid event")

ErrInvalidEvent is returned when an invalid event is published

Functions

func NewMemoryEventBus

func NewMemoryEventBus(logger logging.Logger) events.EventBus

NewMemoryEventBus creates a new memory-based event bus

func NewMemoryPublisher

func NewMemoryPublisher(logger logging.Logger) event.Publisher

NewMemoryPublisher creates a new in-memory event publisher

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) Publish

func (b *MemoryEventBus) Publish(ctx context.Context, event events.Event) error

Publish publishes an event to all subscribers

func (*MemoryEventBus) PublishBatch

func (b *MemoryEventBus) PublishBatch(ctx context.Context, eventList []events.Event) error

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) Publish

func (p *MemoryPublisher) Publish(
	ctx context.Context,
	evt event.Event,
) error

Publish publishes an event to memory

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

Jump to

Keyboard shortcuts

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