Documentation
¶
Overview ¶
Package eventbus provides a simple publish/subscribe event bus. Plugins and components can optionally use this to communicate with each other.
Index ¶
Constants ¶
const (
// PluginName identifies this plugin.
PluginName = "eventbus"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventBus ¶
type EventBus interface {
// Subscribe registers a handler that receives all published messages.
Subscribe(topic string, handler Handler)
// Publish sends a message to all subscribers of the topic.
Publish(topic string, data any)
// Wait blocks until locally-initiated operations complete. For in-memory
// implementations, this means all handlers have finished. For distributed
// implementations, this means messages have been sent to the remote system.
Wait(ctx context.Context) error
}
EventBus provides publish/subscribe with broadcast semantics. All subscribers receive every published message.
func FromContext ¶
FromContext retrieves the event bus from a context.
type EventBusPlugin ¶
type EventBusPlugin struct {
EventBus
}
EventBusPlugin provides access to an event bus for plugins and components to communicate with each other.
func Plugin ¶
func Plugin(eb EventBus) *EventBusPlugin
Plugin registers an eventbus with a Prefab server for use by other plugins to use. The bus can be retrieved from the request context using the FromContext function.
func (*EventBusPlugin) ServerOptions ¶
func (p *EventBusPlugin) ServerOptions() []prefab.ServerOption
From prefab.OptionProvider.
type Message ¶
type Message struct {
ID string // Unique identifier
Topic string // Topic name
Data any // Payload
Attempt int // Delivery attempt (1-based)
// contains filtered or unexported fields
}
Message wraps event data with metadata.
func NewMessage ¶
NewMessage creates a message with default no-op ack/nack functions.
func NewMessageWithCallbacks ¶
NewMessageWithCallbacks creates a message with custom ack/nack callbacks.
type Shutdownable ¶
Shutdownable is implemented by EventBus implementations that need graceful shutdown.