Files

35 lines
1.5 KiB
Go

package inbound
import (
"context"
"errors"
"lincodex/backend/internal/port/outbound"
)
// ErrEventRejected marks a handler failure that a retry cannot fix, for
// example an unsupported schema_version or a payload that breaks the
// contract of its event type. The consumer dead-letters the event at once
// instead of retrying it.
var ErrEventRejected = errors.New("event rejected by handler")
// EventHandler applies domain events from the event bus to this service's
// own state. The consumer runtime calls Handle inside the transaction that
// records the event as processed, so the effect and the dedup marker commit
// together and a repeated delivery is skipped.
type EventHandler interface {
// ConsumerName is a stable snake_case name of at most 64 characters. It
// scopes deduplication and names the consumer group, so renaming it
// makes the consumer process every retained event again.
ConsumerName() string
// Handles reports whether the handler applies events of eventType.
// Other events are acknowledged without a transaction.
Handles(eventType string) bool
// Handle applies event with unit and the context it receives only. An
// error rolls back the effect and the marker. An error matching
// ErrEventRejected is final; any other error is retried with backoff a
// bounded number of times. Errors must not quote the payload or personal
// data, because the reason is logged and stored with the dead letter.
Handle(ctx context.Context, unit outbound.UnitOfWork, event outbound.ConsumedEvent) error
}