API Reference

Full API documentation is available on pkg.go.dev. This page is an index: every exported function and type of the eight library packages, grouped by theme, with a link to its documentation.

Packages

Package Description Link
event Core interfaces (Event, Bus, Invoker, Registry, Observer), LocalBus, the failure model and the DLQ record pkg.go.dev
invoker Execution pipeline components: chain, retry, circuit breaker, rate limiter, idempotency, DLQ pkg.go.dev
json JSON serialization with envelope format pkg.go.dev
jetstream NATS JetStream transport, DLQ publisher and replayer pkg.go.dev
nats NATS Core transport pkg.go.dev
redis Redis-backed idempotency and rate-limit stores pkg.go.dev
telemetry OpenTelemetry: tracing, span events and OTel metrics pkg.go.dev
prometheus Observer with a fixed Prometheus metric set pkg.go.dev

The root package is imported as event. Every name removed or renamed in v0.4.0 is listed in the CHANGELOG, which is the migration guide.

Core (event)

Events, buses and subscribers

  • Event - Base event interface: Name() string
  • WithId - Optional interface: an event chooses its own message id (Id() string)
  • WithVersion - Optional interface: the schema version of an event (Version() int)
  • OnErr - Optional interface: the event’s own failure callback, called after Observer.Failure
  • Bus - Bus interface (Subscribe, Close)
  • SyncBus - Synchronous dispatch interface (EmitSync returns (Event, error))
  • Shutdowner - Optional bus interface: graceful Shutdown(ctx) that drains in-flight handlers
  • RegisterSubscribers - Bulk registration of Subscriber values on a bus
  • Subscriber - Grouped handler interface
  • SubscribeOptionsProvider - Optional interface for subscriber-level subscribe options
  • HandleFn - Handler function type, func(context.Context, Event) error
  • HandlerFunc - Generic typed handler, func(ctx, E) error
  • Invoker - Middleware interface
  • LocalBus - In-process bus
  • NewLocalBus - Creates a LocalBus from its options
  • LocalBusOptions - LocalBus configuration: Invoker, Observer, DLQPublisher, MaxConcurrent, Overflow and more
  • OverflowPolicy - What LocalBus does with an external emit when every slot is busy and the queue is full
  • Lifecycle - Shutdown state machine shared by every bus: admission, in-flight accounting, bounded drain

Emit and subscribe options

Registry, envelope and decode

  • Registry - Serialization interface
  • Envelope - Wire format
  • Factory - Creates a new empty event instance for the registry
  • Upcaster - Migrates a payload from one schema version to the next
  • EnvelopeEncoder - Optional registry interface: EncodeWith encodes with already resolved Metadata
  • EncodeEvent - Encodes with EncodeWith when the registry implements EnvelopeEncoder, else Encode
  • DecodeError - Wraps a decode failure with the event name and version; errors.Is and errors.As both work
  • WrapDecodeError - Wraps an error as a *DecodeError unless it already is one

Context and metadata

  • Metadata - Identity, causal lineage and headers of one event, read by handlers
  • WithMetadata - Returns a context that carries a Metadata
  • MetadataFromContext - Reads the Metadata of the event being handled from the handler context
  • ResolveOutbound - Resolves the Metadata of an event about to be emitted (id, correlation, causation, headers)
  • NewID - Generates a UUIDv7 message id
  • WithID - Sets the message id of an emitted event
  • WithCorrelationID - Sets the correlation id of an emitted event
  • WithHeader - Attaches a user header to an emitted event (repeatable)
  • Delivery - Count, maximum, subject, raw bytes, headers and stream position of one delivery attempt, carried in the handler context
  • WithDelivery - Returns a context that carries a Delivery
  • DeliveryFromContext - Reads the Delivery of the message being handled
  • Execution - The handler run in progress: handler name and start time
  • WithExecution - Returns a context that carries an Execution
  • ExecutionFromContext - Reads the Execution of the handler being run

Failure semantics and DLQ

  • InvokeHandler - The single handler entry point of every transport: runs the chain, recovers panics, emits HandlerDone
  • Settle - The one post-chain policy shared by every transport: dispose, dead-letter backstop, report once
  • SettleInput - What Settle needs to decide the fate of one handled message
  • Settlement - The decision Settle reached
  • Dispose - Maps a handler chain error to a Disposition for a given Delivery
  • Disposition - What a transport does with a message: Ack, Retry, RetryDelayed or Terminal
  • Outcome - Terminal result Settle reports; values are metric label values and never change
  • OutcomeOf - Maps a handler chain error to the HandlerDone outcome
  • ReasonOf - Returns the stable reason code for an error
  • FailureError - Failure of a handler after the in-process retry policy: attempts and history
  • AttemptsOf - How many in-process handler attempts led to an error
  • Attempt - One in-process handler attempt of a delivery
  • NewAttempt - Builds an Attempt
  • AttemptClass - Class of an attempt error: transient, terminal, timeout or panic (closed set)
  • AttemptClassOf - Classifies the error of one attempt
  • FailingInvoker - Names the part of the pipeline that produced a terminal failure (closed set)
  • FailingInvokerOf - Names the part of the pipeline that produced an error
  • PanicError - A panic recovered from a handler or an invoker
  • HandlerError - Identifies the failing handler inside the error LocalBus.EmitSync returns
  • DeadLetteredError - Returned by the DLQ invoker once the message was dead-lettered
  • DeadLetterFailedError - Returned when publishing to the dead-letter queue failed
  • IsInterrupted - Reports whether an error is the result of the subscription context ending
  • WrapInterrupted - Marks a handler error caused by a shutdown
  • DLQPublisher - Publishes a failed message to a dead-letter queue
  • DLQRecord - Everything a publisher needs to dead-letter one message: original bytes, headers, cause
  • NewDLQRecord - Builds the DLQRecord for a message that failed with a cause
  • PublishDeadLetter - Publishes a record through a publisher and reports DeadLettered or DLQPublishFailed
  • MemoryDLQ - In-memory DLQPublisher for tests and examples
  • NewMemoryDLQ - Returns an empty MemoryDLQ
  • EncodeHistoryHeader - Encodes the retry history as the Eventbus-Dlq-History header value
  • TruncateHeader - Makes a string safe to use as a header value of bounded size

Observability

Constant groups, by their first name: OutcomeOK (Outcome values), ReasonTerminal (Reason codes), ComponentTransport (InternalError components), OpConsume (InternalError operations), DispositionAck (Disposition values), BreakerClosed and BreakerReasonFailureThreshold (breaker values), AttemptTransient (AttemptClass values), InvokerRetry (FailingInvoker values), OverflowBlock (OverflowPolicy values), HeaderDLQPrefix and HeaderDLQTraceparent (dead-letter and replay header names), and DefaultMaxConcurrent (LocalBus and shutdown defaults).

Error values

JSON Registry

  • Registry - JSON registry: encodes, decodes and upcasts envelopes
  • NewRegistry - Returns an empty Registry; options are optional
  • Option - Functional option for json.NewRegistry
  • WithPropagator - Replaces the default W3C trace context and baggage propagator
  • WithIDGenerator - Sets the id generator used for events without an explicit id
  • EncodeWith - Encodes an event with explicit Metadata

Invoker

The names below also have error values re-exported from the root package: ErrDuplicate, ErrRateLimited, ErrCircuitOpen and ErrSendToDLQ.

NATS Core

  • Bus - NATS Core bus
  • NewNatsBus - Creates a Bus over a NATS connection and a registry
  • BusOptions - Invoker, Observer, DLQPublisher, ReplyErrorMessage, request timeout and shutdown options
  • RemoteError - What EmitSync returns when the responder replied with an Eventbus-Error header

JetStream

  • Bus - JetStream bus
  • NewBus - Creates a Bus over a JetStream backend and a registry
  • BusOptions - Invoker, Observer, DLQPublisher, publish retry, redelivery delays and shutdown options
  • PublishRetryPolicy - Bounds the internal retry of transient publish failures
  • DLQ - Publishes dead-lettered messages to JetStream with the original bytes
  • NewDLQ - Creates a DLQ for a prefix (default dlq.)
  • DLQOption - Option for NewDLQ
  • WithDLQRegistry - Sets the registry that encodes a record with no original bytes
  • Replayer - Republishes dead-lettered messages from a DLQ stream
  • NewReplayer - Creates a Replayer
  • ReplayerOption - Option for NewReplayer
  • WithReplayTracerProvider - Sets the provider of the replay spans
  • ReplayOptions - What Replay reads and where it publishes
  • ReplayResult - Counts the records handled by one Replay call
  • ErrStreamRequired - Subscribe called without WithStream
  • ErrInvalidConfig - Invalid consumer configuration (for example MaxDeliver inconsistent with the backoff length)
  • ErrNoEnvelope - A record with neither original bytes nor a registry cannot be encoded
  • ErrReplaySubject - A replay record has no valid target subject

Redis

Telemetry

Prometheus

  • Observer - event.Observer with a fixed set of Prometheus metric families
  • NewObserver - Registers the metric set on a registerer and returns the Observer
  • Option - Option for NewObserver
  • WithNamespace - Prefixes every metric name with a namespace

Back to top

Copyright © 2025 Isaque de Souza Barbosa. Distributed under the MIT License.