Events API

Piko wraps Watermill for typed in-process or distributed event messaging. Two backends ship by default. In-memory GoChannel and NATS. The facade exposes shared router, publisher, and subscriber instances that Piko builds once and shares across the application. For task recipes see the background tasks how-to. Source file: wdk/events/facade.go.

Accessors

FunctionReturns
events.GetRouter() (*message.Router, error)The shared router.
events.GetPublisher() (message.Publisher, error)The shared publisher.
events.GetSubscriber() (message.Subscriber, error)The shared subscriber.
events.GetProvider() (Provider, error)The underlying provider.
events.IsRunning() boolWhether the router is running.

The message.* types come from github.com/ThreeDotsLabs/watermill/message. Piko does not re-export them.

Types

TypePurpose
ProviderBackend-agnostic bus provider.
ProviderConfigShared settings.
RouterConfigRouter-specific settings.

Logger adapter

events.NewWatermillLoggerAdapter(l logger.Logger) watermill.LoggerAdapter

Bridges Piko's logger into Watermill so messages land in the same structured-log pipeline as the rest of the application.

Defaults

events.DefaultProviderConfig() returns the default config (in-memory GoChannel with back-pressure enabled).

Providers

Sub-packageBackend
events_provider_gochannelIn-memory (default).
events_provider_natsNATS message broker.

Bootstrap options

OptionPurpose
piko.WithEventsProvider(provider)Replaces the default provider.

See also