eventbus

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus is an in-process event bus for cross-service communication within cloudmock.

func NewBus

func NewBus() *Bus

NewBus creates a new event bus.

func (*Bus) HasSubscribers

func (b *Bus) HasSubscribers() bool

HasSubscribers returns true if there is at least one subscription. Useful for callers to skip event construction when nobody is listening.

func (*Bus) Publish

func (b *Bus) Publish(event *Event)

Publish fans out an event to all matching subscriptions asynchronously. Each matching handler is invoked in its own goroutine. Errors from handlers are silently discarded (fire-and-forget semantics).

func (*Bus) PublishSync

func (b *Bus) PublishSync(event *Event) []error

PublishSync fans out an event to all matching subscriptions synchronously. This is useful in tests where you need to wait for delivery to complete.

func (*Bus) Subscribe

func (b *Bus) Subscribe(sub *Subscription) string

Subscribe registers a subscription on the bus. Returns the subscription ID. If sub.ID is empty, a random ID is generated.

func (*Bus) Unsubscribe

func (b *Bus) Unsubscribe(id string)

Unsubscribe removes the subscription with the given ID.

type Event

type Event struct {
	Source    string         // service that produced the event, e.g. "s3"
	Type      string         // event type, e.g. "s3:ObjectCreated:Put"
	Detail    map[string]any // event payload
	Time      time.Time
	Region    string
	AccountID string
}

Event represents an internal cross-service event within cloudmock.

type EventHandler

type EventHandler func(event *Event) error

EventHandler is a callback invoked when a matching event is published.

type Subscription

type Subscription struct {
	ID      string
	Source  string   // filter by source service
	Types   []string // filter by event types (supports prefix matching with *)
	Handler EventHandler
}

Subscription describes a listener registered on the event bus.

Jump to

Keyboard shortcuts

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