watermill

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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

func NewEventBus(bufferSize int64, persistent bool, debug bool) *EventBus

NewEventBus creates a configured in-memory Channel PubSub.

func (*EventBus) Close

func (w *EventBus) Close(ctx context.Context) error

Close cancels all active subscriptions, waits for running handlers to exit, and shuts down the underlying Channel.

func (*EventBus) Publish

func (w *EventBus) Publish(ctx context.Context, topic string, payload []byte) error

Publish generates a Watermill-compatible message, propagates context, and sends it.

func (*EventBus) Subscribe

func (w *EventBus) Subscribe(ctx context.Context, topic string, handler modulex.EventHandler) error

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.

Jump to

Keyboard shortcuts

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