Documentation
¶
Index ¶
- Constants
- func NewModule() modular.Module
- type Event
- type EventBus
- type EventBusConfig
- type EventBusModule
- func (m *EventBusModule) Constructor() modular.ModuleConstructor
- func (m *EventBusModule) Dependencies() []string
- func (m *EventBusModule) Init(app modular.Application) error
- func (m *EventBusModule) Name() string
- func (m *EventBusModule) ProvidesServices() []modular.ServiceProvider
- func (m *EventBusModule) Publish(ctx context.Context, topic string, payload interface{}) error
- func (m *EventBusModule) RegisterConfig(app modular.Application) error
- func (m *EventBusModule) RequiresServices() []modular.ServiceDependency
- func (m *EventBusModule) Start(ctx context.Context) error
- func (m *EventBusModule) Stop(ctx context.Context) error
- func (m *EventBusModule) Subscribe(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
- func (m *EventBusModule) SubscribeAsync(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
- func (m *EventBusModule) SubscriberCount(topic string) int
- func (m *EventBusModule) Topics() []string
- func (m *EventBusModule) Unsubscribe(ctx context.Context, subscription Subscription) error
- type EventHandler
- type MemoryEventBus
- func (m *MemoryEventBus) Publish(ctx context.Context, event Event) error
- func (m *MemoryEventBus) Start(ctx context.Context) error
- func (m *MemoryEventBus) Stop(ctx context.Context) error
- func (m *MemoryEventBus) Subscribe(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
- func (m *MemoryEventBus) SubscribeAsync(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
- func (m *MemoryEventBus) SubscriberCount(topic string) int
- func (m *MemoryEventBus) Topics() []string
- func (m *MemoryEventBus) Unsubscribe(ctx context.Context, subscription Subscription) error
- type Subscription
Constants ¶
const ModuleName = "eventbus"
ModuleName is the name of this module
const ServiceName = "eventbus.provider"
ServiceName is the name of the service provided by this module
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
// Topic is the channel or subject of the event
Topic string `json:"topic"`
// Payload is the data associated with the event
Payload interface{} `json:"payload"`
// Metadata contains additional information about the event
Metadata map[string]interface{} `json:"metadata,omitempty"`
// CreatedAt is when the event was created
CreatedAt time.Time `json:"createdAt"`
// ProcessingStarted is when the event processing started
ProcessingStarted *time.Time `json:"processingStarted,omitempty"`
// ProcessingCompleted is when the event processing completed
ProcessingCompleted *time.Time `json:"processingCompleted,omitempty"`
}
Event represents a message in the event bus
type EventBus ¶
type EventBus interface {
// Start initializes the event bus
Start(ctx context.Context) error
// Stop shuts down the event bus
Stop(ctx context.Context) error
// Publish sends an event to the specified topic
Publish(ctx context.Context, event Event) error
// Subscribe registers a handler for a topic with synchronous processing
Subscribe(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
// SubscribeAsync registers a handler for a topic with asynchronous processing
SubscribeAsync(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
// Unsubscribe removes a subscription
Unsubscribe(ctx context.Context, subscription Subscription) error
// Topics returns a list of all active topics
Topics() []string
// SubscriberCount returns the number of subscribers for a topic
SubscriberCount(topic string) int
}
EventBus defines the interface for an event bus implementation
type EventBusConfig ¶
type EventBusConfig struct {
// Engine specifies the event bus engine to use ("memory", "redis", "kafka", etc.)
Engine string `json:"engine" yaml:"engine" validate:"oneof=memory redis kafka"`
// MaxEventQueueSize is the maximum number of events to queue per topic
MaxEventQueueSize int `json:"maxEventQueueSize" yaml:"maxEventQueueSize" validate:"min=1"`
// DefaultEventBufferSize is the default buffer size for subscription channels
DefaultEventBufferSize int `json:"defaultEventBufferSize" yaml:"defaultEventBufferSize" validate:"min=1"`
// WorkerCount is the number of worker goroutines for async event processing
WorkerCount int `json:"workerCount" yaml:"workerCount" validate:"min=1"`
// EventTTL is the time to live for events in seconds
EventTTL int `json:"eventTTL" yaml:"eventTTL" validate:"min=1"`
// RetentionDays is how many days to retain event history
RetentionDays int `json:"retentionDays" yaml:"retentionDays" validate:"min=1"`
// External broker configuration
ExternalBrokerURL string `json:"externalBrokerURL" yaml:"externalBrokerURL"`
ExternalBrokerUser string `json:"externalBrokerUser" yaml:"externalBrokerUser"`
ExternalBrokerPassword string `json:"externalBrokerPassword" yaml:"externalBrokerPassword"`
}
EventBusConfig defines the configuration for the event bus module
type EventBusModule ¶
type EventBusModule struct {
// contains filtered or unexported fields
}
EventBusModule represents the event bus module
func (*EventBusModule) Constructor ¶
func (m *EventBusModule) Constructor() modular.ModuleConstructor
Constructor provides a dependency injection constructor for the module
func (*EventBusModule) Dependencies ¶
func (m *EventBusModule) Dependencies() []string
Dependencies returns the names of modules this module depends on
func (*EventBusModule) Init ¶
func (m *EventBusModule) Init(app modular.Application) error
Init initializes the module
func (*EventBusModule) Name ¶
func (m *EventBusModule) Name() string
Name returns the name of the module
func (*EventBusModule) ProvidesServices ¶
func (m *EventBusModule) ProvidesServices() []modular.ServiceProvider
ProvidesServices declares services provided by this module
func (*EventBusModule) Publish ¶
func (m *EventBusModule) Publish(ctx context.Context, topic string, payload interface{}) error
Publish publishes an event to the event bus
func (*EventBusModule) RegisterConfig ¶
func (m *EventBusModule) RegisterConfig(app modular.Application) error
RegisterConfig registers the module's configuration structure
func (*EventBusModule) RequiresServices ¶
func (m *EventBusModule) RequiresServices() []modular.ServiceDependency
RequiresServices declares services required by this module
func (*EventBusModule) Start ¶
func (m *EventBusModule) Start(ctx context.Context) error
Start performs startup logic for the module
func (*EventBusModule) Stop ¶
func (m *EventBusModule) Stop(ctx context.Context) error
Stop performs shutdown logic for the module
func (*EventBusModule) Subscribe ¶
func (m *EventBusModule) Subscribe(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
Subscribe subscribes to a topic on the event bus
func (*EventBusModule) SubscribeAsync ¶
func (m *EventBusModule) SubscribeAsync(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
SubscribeAsync subscribes to a topic with asynchronous event handling
func (*EventBusModule) SubscriberCount ¶
func (m *EventBusModule) SubscriberCount(topic string) int
SubscriberCount returns the number of subscribers for a topic
func (*EventBusModule) Topics ¶
func (m *EventBusModule) Topics() []string
Topics returns a list of all active topics
func (*EventBusModule) Unsubscribe ¶
func (m *EventBusModule) Unsubscribe(ctx context.Context, subscription Subscription) error
Unsubscribe cancels a subscription
type EventHandler ¶
EventHandler is a function that handles an event
type MemoryEventBus ¶
type MemoryEventBus struct {
// contains filtered or unexported fields
}
MemoryEventBus implements EventBus using in-memory channels
func NewMemoryEventBus ¶
func NewMemoryEventBus(config *EventBusConfig) *MemoryEventBus
NewMemoryEventBus creates a new in-memory event bus
func (*MemoryEventBus) Publish ¶
func (m *MemoryEventBus) Publish(ctx context.Context, event Event) error
Publish sends an event to the specified topic
func (*MemoryEventBus) Start ¶
func (m *MemoryEventBus) Start(ctx context.Context) error
Start initializes the event bus
func (*MemoryEventBus) Stop ¶
func (m *MemoryEventBus) Stop(ctx context.Context) error
Stop shuts down the event bus
func (*MemoryEventBus) Subscribe ¶
func (m *MemoryEventBus) Subscribe(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
Subscribe registers a handler for a topic
func (*MemoryEventBus) SubscribeAsync ¶
func (m *MemoryEventBus) SubscribeAsync(ctx context.Context, topic string, handler EventHandler) (Subscription, error)
SubscribeAsync registers a handler for a topic with asynchronous processing
func (*MemoryEventBus) SubscriberCount ¶
func (m *MemoryEventBus) SubscriberCount(topic string) int
SubscriberCount returns the number of subscribers for a topic
func (*MemoryEventBus) Topics ¶
func (m *MemoryEventBus) Topics() []string
Topics returns a list of all active topics
func (*MemoryEventBus) Unsubscribe ¶
func (m *MemoryEventBus) Unsubscribe(ctx context.Context, subscription Subscription) error
Unsubscribe removes a subscription
type Subscription ¶
type Subscription interface {
// Topic returns the topic being subscribed to
Topic() string
// ID returns the unique identifier for this subscription
ID() string
// IsAsync returns true if this is an asynchronous subscription
IsAsync() bool
// Cancel cancels the subscription
Cancel() error
}
Subscription represents a subscription to a topic