messaging

package
v0.23.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ModuleName = "messaging"
)

Variables

View Source
var (
	ErrUnknownModule = fmt.Errorf("module is not the %s module", ModuleName)
)

Functions

func New

func New() modules.Module

func WithDeliveriesTable added in v0.18.0

func WithDeliveriesTable(tableName string) modules.Option

WithDeliveriesTable sets the database table name holding the per-subscriber delivery rows of the outbox events.

func WithDispatcherDeliveryTimeout

func WithDispatcherDeliveryTimeout(deliveryTimeout time.Duration) modules.Option

WithDispatcherDeliveryTimeout sets the maximum duration allowed for a batch of events to be delivered before timing out. This acts as a safeguard against workers hanging indefinitely.

func WithDispatcherEnabled

func WithDispatcherEnabled() modules.Option

WithDispatcherEnabled enables the dispatcher loop. When set, the module will poll the outbox table and listen on the notify channel for new messages. Without this option, the dispatcher will not run.

func WithDispatcherListenerMaxBackoff added in v0.18.0

func WithDispatcherListenerMaxBackoff(maxBackoff time.Duration) modules.Option

WithDispatcherListenerMaxBackoff is how long the notification listener waits between attempts once its backoff has ramped all the way up, per WithDispatcherListenerMaxRetries.

func WithDispatcherListenerMaxRetries added in v0.18.0

func WithDispatcherListenerMaxRetries(maxRetries int) modules.Option

WithDispatcherListenerMaxRetries sets how many consecutive failed listener attempts the backoff — the same curve used for delivery retries — ramps over before it plateaus at the value set by WithDispatcherListenerMaxBackoff. Unlike a delivery, the listener never gives up: past this many failures it keeps retrying indefinitely, always waiting the max backoff between attempts. Polling still delivers events while the listener is down, so this is about restoring low-latency delivery once the database is reachable again, not correctness.

func WithDispatcherMaxDeliveryRetries

func WithDispatcherMaxDeliveryRetries(maxDeliveryRetries int) modules.Option

WithDispatcherMaxDeliveryRetries sets the maximum number of delivery attempts before an event is considered permanently failed and no longer retried.

func WithDispatcherMaxRetryBackoff added in v0.18.0

func WithDispatcherMaxRetryBackoff(maxBackoff time.Duration) modules.Option

WithDispatcherMaxRetryBackoff sets how long the last allowed retry of a failed delivery waits. The first retry is immediate and the ones in between grow exponentially towards it.

func WithDispatcherMaxWorkers

func WithDispatcherMaxWorkers(maxWorkers int) modules.Option

WithDispatcherMaxWorkers sets the maximum number of concurrent worker goroutines used by the dispatcher to process and deliver events in parallel.

func WithDispatcherPollInterval

func WithDispatcherPollInterval(pollInterval time.Duration) modules.Option

WithDispatcherPollInterval sets how often the dispatcher polls the outbox table for new events when no notifications are received on the notify channel.

func WithDispatcherStartFrom added in v0.18.0

func WithDispatcherStartFrom(startFrom time.Time) modules.Option

WithDispatcherStartFrom bounds how far back the dispatcher fans events out to its subscribers: events created before the given time never get a delivery row. Delivery rows that already exist are delivered regardless of age. Use it so a newly registered subscriber does not replay history.

func WithEventSigningSecret added in v0.18.0

func WithEventSigningSecret(signingSecret string) modules.Option

WithEventSigningSecret sets the secret the body of every webhook delivery is signed with. Receivers verify the signature with the same secret.

func WithOutboxIgnoreNoTx

func WithOutboxIgnoreNoTx(ignoreNoTx bool) modules.Option

WithOutboxIgnoreNoTx configures whether inserting outbox events outside of an active transaction should be ignored instead of returning an error. By default, this is disabled (false).

func WithOutboxNotifyChannel

func WithOutboxNotifyChannel(notifyChannel string) modules.Option

WithOutboxNotifyChannel sets the database NOTIFY channel used to signal listeners when new events are inserted into the outbox table. The same channel is also used by the dispatcher when enabled.

func WithOutboxRetention added in v0.18.0

func WithOutboxRetention(retention time.Duration) modules.Option

WithOutboxRetention makes the module delete events older than the given duration, along with their delivery rows, on a periodic sweep. Without it nothing is ever deleted, and cleaning up is the service's own business. Choose a retention comfortably longer than the retry budget: a sweep does not care whether an event was ever delivered.

func WithOutboxSendNotify

func WithOutboxSendNotify(sendNotify bool) modules.Option

WithOutboxSendNotify configures whether the outbox should send an explicit PostgreSQL NOTIFY after inserting a new event. By default, this is disabled (false).

func WithOutboxTable

func WithOutboxTable(tableName string) modules.Option

WithOutboxTable sets the database table name used by the outbox to store and track pending events before they are dispatched.

func WithSubscriberName added in v0.18.0

func WithSubscriberName(subscriberName string) modules.Option

WithSubscriberName sets the name this service is recorded under in the delivery rows of the events it handles in process. Webhook deliveries are recorded under the name of the remote subscriber instead, so a service that only sends webhooks needs no name of its own. It is stored in the database, so it must stay stable across restarts: changing it orphans the existing delivery rows and re-delivers every event still within the cutoff. It is required to register in process handlers.

func WithWebhookHTTPClient added in v0.18.0

func WithWebhookHTTPClient(client *http.Client) modules.Option

WithWebhookHTTPClient sets the HTTP client used for webhook deliveries, for a service that needs its own transport, timeout or instrumentation. Without it, deliveries use a client whose timeout is the dispatcher's delivery timeout.

func WithWebhookHeader added in v0.18.0

func WithWebhookHeader(key, value string) modules.Option

WithWebhookHeader adds a header sent with every webhook delivery, on top of the signature and event id headers. Use it for whatever the receiving side authenticates with, an internal API key for example. It is repeatable.

Types

type Module

type Module struct {
	modules.Base
	// contains filtered or unexported fields
}

func (*Module) Configure

func (m *Module) Configure(opts ...modules.Option) error

func (*Module) Dispatcher

func (m *Module) Dispatcher() *dispatcher.Dispatcher

func (*Module) Outbox

func (m *Module) Outbox() *outbox.Outbox

func (*Module) Shutdown

func (m *Module) Shutdown() error

func (*Module) Start

func (m *Module) Start() error

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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