Documentation
¶
Overview ¶
Package middleware defines the publish-side and consume-side middleware contracts used by the event bus. Middleware composes orthogonal concerns (tracing, logging, metrics, idempotency, panic recovery) so that transports and handlers stay focused.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsumeHandler ¶
ConsumeHandler is the inner function a ConsumeMiddleware wraps. The Delivery is exposed so middleware can inspect Attempt counts and Ack/Nack the message directly (e.g. inbox dedupe).
func ChainConsume ¶
func ChainConsume(mws []ConsumeMiddleware, caps transport.Capabilities, base ConsumeHandler) ConsumeHandler
ChainConsume composes consume middlewares filtered by transport capabilities. The first applicable middleware becomes the outermost wrapper. Nil entries are skipped (see ChainPublish).
type ConsumeMiddleware ¶
type ConsumeMiddleware interface {
// Name identifies the middleware for ordering and diagnostics.
Name() string
// Applies reports whether the middleware should attach to a
// transport with the given capabilities. For example, Inbox
// returns false on non-AtLeastOnce transports to avoid pointless
// database writes.
Applies(caps transport.Capabilities) bool
// WrapConsume returns a new handler that wraps next.
WrapConsume(next ConsumeHandler) ConsumeHandler
}
ConsumeMiddleware augments the consume pipeline. Implementations run before the user-registered handler and may transform context, log, dedupe, capture metrics, recover panics, etc.
type PublishHandler ¶
PublishHandler is the inner function a PublishMiddleware wraps.
func ChainPublish ¶
func ChainPublish(mws []PublishMiddleware, base PublishHandler) PublishHandler
ChainPublish composes middlewares in order: the first element in mws becomes the outermost wrapper. Nil entries are skipped so opt-out constructors (returning nil under disabled feature flags) compose safely with fx groups.
type PublishMiddleware ¶
type PublishMiddleware interface {
// Name identifies the middleware for ordering and diagnostics.
Name() string
// WrapPublish returns a new handler that wraps next with the
// middleware's behavior.
WrapPublish(next PublishHandler) PublishHandler
}
PublishMiddleware augments the publish pipeline. Implementations can mutate the Envelope (e.g. inject tracing headers) before invoking next, or short-circuit by returning without calling next.