Documentation
¶
Overview ¶
Package bus provides the core event bus functionality for pub/sub messaging.
Index ¶
- type Config
- type Event
- type EventBus
- func (eb *EventBus) Close()
- func (eb *EventBus) Publish(ctx context.Context, event Event) error
- func (eb *EventBus) PublishAsync(ctx context.Context, event Event)
- func (eb *EventBus) Subscribe(eventType EventType, subscriber Subscriber)
- func (eb *EventBus) SubscriberCount(eventType EventType) int
- func (eb *EventBus) Unsubscribe(eventType EventType, subscriber Subscriber)
- type EventType
- type Logger
- type Subscriber
- type SubscriberFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
ID string `json:"id"`
Type EventType `json:"type"`
Source string `json:"source"`
Timestamp time.Time `json:"timestamp"`
Data map[string]interface{} `json:"data"`
Metadata map[string]string `json:"metadata"`
}
Event represents an event in the system.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus manages event subscriptions and publishes events to subscribers.
func NewEventBus ¶
NewEventBus creates a new EventBus with the given logger.
func NewEventBusWithConfig ¶
NewEventBusWithConfig creates a new EventBus with the given logger and configuration.
func (*EventBus) Close ¶
func (eb *EventBus) Close()
Close gracefully shuts down the event bus, draining the async buffer.
func (*EventBus) Publish ¶
Publish sends an event to all subscribers of the event type. Errors from individual subscribers are logged but don't affect other subscribers.
func (*EventBus) PublishAsync ¶
PublishAsync queues an event for asynchronous processing. Returns immediately without waiting for subscribers.
func (*EventBus) Subscribe ¶
func (eb *EventBus) Subscribe(eventType EventType, subscriber Subscriber)
Subscribe adds a subscriber for the given event type.
func (*EventBus) SubscriberCount ¶
SubscriberCount returns the number of subscribers for an event type.
func (*EventBus) Unsubscribe ¶
func (eb *EventBus) Unsubscribe(eventType EventType, subscriber Subscriber)
Unsubscribe removes a subscriber for the given event type.
type EventType ¶
type EventType string
EventType represents the type of an event.
const ( EventWorkflowStarted EventType = "workflow.started" EventWorkflowCompleted EventType = "workflow.completed" EventWorkflowFailed EventType = "workflow.failed" )
Event types for workflow lifecycle.
type Logger ¶
type Logger interface {
Info(msg string, args ...any)
Error(msg string, args ...any)
Debug(msg string, args ...any)
Warn(msg string, args ...any)
}
Logger is the interface for logging within the event bus.