Documentation
¶
Index ¶
- Constants
- Variables
- func New() modules.Module
- func WithDeliveriesTable(tableName string) modules.Option
- func WithDispatcherDeliveryTimeout(deliveryTimeout time.Duration) modules.Option
- func WithDispatcherEnabled() modules.Option
- func WithDispatcherListenerMaxBackoff(maxBackoff time.Duration) modules.Option
- func WithDispatcherListenerMaxRetries(maxRetries int) modules.Option
- func WithDispatcherMaxDeliveryRetries(maxDeliveryRetries int) modules.Option
- func WithDispatcherMaxRetryBackoff(maxBackoff time.Duration) modules.Option
- func WithDispatcherMaxWorkers(maxWorkers int) modules.Option
- func WithDispatcherPollInterval(pollInterval time.Duration) modules.Option
- func WithDispatcherStartFrom(startFrom time.Time) modules.Option
- func WithEventSigningSecret(signingSecret string) modules.Option
- func WithOutboxIgnoreNoTx(ignoreNoTx bool) modules.Option
- func WithOutboxNotifyChannel(notifyChannel string) modules.Option
- func WithOutboxRetention(retention time.Duration) modules.Option
- func WithOutboxSendNotify(sendNotify bool) modules.Option
- func WithOutboxTable(tableName string) modules.Option
- func WithSubscriberName(subscriberName string) modules.Option
- func WithWebhookHTTPClient(client *http.Client) modules.Option
- func WithWebhookHeader(key, value string) modules.Option
- type Module
Constants ¶
const (
ModuleName = "messaging"
)
Variables ¶
var (
ErrUnknownModule = fmt.Errorf("module is not the %s module", ModuleName)
)
Functions ¶
func WithDeliveriesTable ¶ added in v0.18.0
WithDeliveriesTable sets the database table name holding the per-subscriber delivery rows of the outbox events.
func WithDispatcherDeliveryTimeout ¶
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 ¶
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
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
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 ¶
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
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 ¶
WithDispatcherMaxWorkers sets the maximum number of concurrent worker goroutines used by the dispatcher to process and deliver events in parallel.
func WithDispatcherPollInterval ¶
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
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
WithEventSigningSecret sets the secret the body of every webhook delivery is signed with. Receivers verify the signature with the same secret.
func WithOutboxIgnoreNoTx ¶
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 ¶
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
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 ¶
WithOutboxSendNotify configures whether the outbox should send an explicit PostgreSQL NOTIFY after inserting a new event. By default, this is disabled (false).
func WithOutboxTable ¶
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
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
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
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 ¶
func (*Module) Dispatcher ¶
func (m *Module) Dispatcher() *dispatcher.Dispatcher