bus

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bus provides the core event bus functionality for pub/sub messaging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AsyncBufferSize int
	WorkerPoolSize  int
}

Config holds configuration for the event bus.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration.

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

func NewEventBus(logger Logger) *EventBus

NewEventBus creates a new EventBus with the given logger.

func NewEventBusWithConfig

func NewEventBusWithConfig(logger Logger, cfg Config) *EventBus

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

func (eb *EventBus) Publish(ctx context.Context, event Event) error

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

func (eb *EventBus) PublishAsync(ctx context.Context, event Event)

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

func (eb *EventBus) SubscriberCount(eventType EventType) int

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.

const (
	EventJobEnqueued  EventType = "job.enqueued"
	EventJobStarted   EventType = "job.started"
	EventJobCompleted EventType = "job.completed"
	EventJobFailed    EventType = "job.failed"
)

Event types for job lifecycle.

const (
	EventAgentExecuted      EventType = "agent.executed"
	EventTestSuiteCompleted EventType = "test.suite.completed"
	EventWebhookTriggered   EventType = "webhook.triggered"
	EventEmailSent          EventType = "email.sent"
)

Event types for other system events.

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.

type Subscriber

type Subscriber interface {
	// Handle processes an event. It should return an error if the event
	// could not be processed successfully.
	Handle(ctx context.Context, event Event) error
}

Subscriber is the interface that must be implemented by event subscribers.

type SubscriberFunc

type SubscriberFunc func(ctx context.Context, event Event) error

SubscriberFunc is a function type that implements the Subscriber interface.

func (SubscriberFunc) Handle

func (f SubscriberFunc) Handle(ctx context.Context, event Event) error

Handle calls the function.

Jump to

Keyboard shortcuts

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