Documentation
¶
Index ¶
- type EventBus
- func (w *EventBus) Close(ctx context.Context) error
- func (w *EventBus) Publish(ctx context.Context, topic string, payload []byte) error
- func (w *EventBus) Subscribe(ctx context.Context, topic string, handler modulex.EventHandler) error
- func (w *EventBus) SubscribeWithOptions(ctx context.Context, topic string, handler modulex.EventHandler, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus implements modulex.EventBus using Watermill's Channel.
func NewEventBus ¶
NewEventBus creates a configured in-memory Channel PubSub.
func (*EventBus) Close ¶
Close cancels all active subscriptions, waits for running handlers to exit, and shuts down the underlying Channel.
func (*EventBus) Publish ¶
Publish generates a Watermill-compatible message, propagates context, and sends it.
func (*EventBus) Subscribe ¶
Subscribe listens to a topic and handles messages in the background.
ctx governs the subscription's lifetime as well as this call: cancelling ctx stops the subscription and releases its goroutine, exactly like calling EventBus.Close would for it. This means a bounded or per-call context (e.g. one scoped only to a module's Init phase, cancelled via a deferred cancel() shortly after Subscribe returns) will silently end the subscription early. Pass a context whose lifetime you intend the subscription to share — typically the same long-lived context used for the surrounding Manager's InitModules/StartModules call, or context.Background() paired with relying on EventBus.Close() alone to stop it.
func (*EventBus) SubscribeWithOptions ¶ added in v0.8.0
func (w *EventBus) SubscribeWithOptions(ctx context.Context, topic string, handler modulex.EventHandler, options workerpool.Options) error
SubscribeWithOptions subscribes with an opt-in bounded processor. Handler errors retain Watermill's existing acknowledge-and-log policy. Messages are acknowledged only after the handler returns. Processing order is not guaranteed when Workers is greater than one. See Subscribe's doc comment for how ctx governs this subscription's lifetime, including after this call returns.