Documentation
¶
Index ¶
- Constants
- Variables
- func AsGoError(err error) *gerrors.Error
- func AsRetryableError(err error) *gerrors.RetryableError
- func ErrorSlogAttributes(err error) []slog.Attr
- func IsMessageError(err error) bool
- func NewMessageError(cause error) error
- type Acknowledger
- type BasicDelivery
- type Capabilities
- type Capability
- type Codec
- type ConsumeDriver
- type Consumer
- type CorrelationRegistry
- type Delivery
- type DeliveryInfo
- type Destination
- type Disposition
- type Driver
- type DriverRegistry
- type Envelope
- type HandleResult
- type Handler
- type Ingress
- type IngressBinding
- type IngressOption
- type JSONCodec
- type Kind
- type LifecycleState
- type MessageError
- type NackOptions
- type NopObserver
- type Observation
- type Observer
- type ObserverFunc
- type Operation
- type PublishDriver
- type PublishOutcome
- type PublishResult
- type Publisher
- type ReplyWaiter
- type Route
- type RouteBinding
- type Router
- type RoutingResult
- type Source
- type Strategy
- type Subscription
- type TransportError
- type ValidationLimits
Constants ¶
const ( TextCodeInvalidEnvelope = "INVALID_ENVELOPE" TextCodeSchemaMismatch = "SCHEMA_MISMATCH" TextCodeMessageTooLarge = "MESSAGE_TOO_LARGE" TextCodeUnknownRoute = "UNKNOWN_ROUTE" TextCodeUnknownDriver = "UNKNOWN_DRIVER" TextCodeUnsupportedCapability = "UNSUPPORTED_CAPABILITY" TextCodePublishRejected = "PUBLISH_REJECTED" TextCodePublishAmbiguous = "PUBLISH_AMBIGUOUS" TextCodeNotPublished = "NOT_PUBLISHED" TextCodeSubscriptionNotReady = "SUBSCRIPTION_NOT_READY" TextCodeSubscriptionClosed = "SUBSCRIPTION_CLOSED" TextCodeReplyTimeout = "REPLY_TIMEOUT" TextCodeCorrelationFailure = "CORRELATION_FAILURE" TextCodeAcknowledgementFailed = "ACKNOWLEDGEMENT_FAILED" TextCodeUnsupportedDisposition = "UNSUPPORTED_DISPOSITION" TextCodeDeadLetterFailed = "DEAD_LETTER_FAILED" TextCodeHandlerPanic = "HANDLER_PANIC" TextCodeMessageHandlingFailed = "MESSAGE_HANDLING_FAILED" TextCodeObservationFailed = "OBSERVATION_FAILED" TextCodeOperationCanceled = "OPERATION_CANCELED" TextCodeOperationDeadlineExceeded = "OPERATION_DEADLINE_EXCEEDED" TextCodeInternalError = "MESSAGING_INTERNAL_ERROR" )
const JSONEnvelopeContentType = "application/vnd.goliatone.messaging-envelope+json"
const ReservedHeaderPrefix = "messaging."
Variables ¶
var ( ErrInvalidEnvelope = errors.New("messaging: invalid envelope") ErrSchemaMismatch = errors.New("messaging: schema mismatch") ErrMessageTooLarge = errors.New("messaging: message too large") )
var ( ErrUnknownRoute = errors.New("messaging: unknown route") ErrUnknownDriver = errors.New("messaging: unknown driver") ErrUnsupportedCapability = errors.New("messaging: unsupported capability") ErrPublishRejected = errors.New("messaging: publish rejected") ErrPublishAmbiguous = errors.New("messaging: publish outcome ambiguous") ErrNotPublished = errors.New("messaging: definitely not published") ErrSubscriptionNotReady = errors.New("messaging: subscription not ready") ErrSubscriptionClosed = errors.New("messaging: subscription closed") ErrReplyTimeout = errors.New("messaging: reply timeout") ErrCorrelation = errors.New("messaging: reply correlation failure") ErrAcknowledgement = errors.New("messaging: acknowledgement failure") ErrUnsupportedDisposition = errors.New("messaging: unsupported disposition") ErrDeadLetter = errors.New("messaging: dead-letter failure") ErrHandlerPanic = errors.New("messaging: handler panic") ErrMessageHandling = errors.New("messaging: message handling failed") ErrObservedOperation = errors.New("messaging: observed operation failed") )
Functions ¶
func AsGoError ¶
AsGoError projects err into the shared structured error contract without changing the error returned by the messaging API. Existing go-errors values pass through unchanged. Package errors retain errors.Is/errors.As behavior through a source wrapper whose Error string is safe to expose.
func AsRetryableError ¶
func AsRetryableError(err error) *gerrors.RetryableError
AsRetryableError projects err as retryable only when its stable messaging class proves that retrying is safe. In particular, ambiguous publications are never retryable even when a transport marks the failure temporary. A non-nil return value is guaranteed to report IsRetryable() == true.
func ErrorSlogAttributes ¶
ErrorSlogAttributes returns structured attributes safe for library logging. It deliberately drops sources, stack/location data, request IDs, validation payloads, and metadata outside the messaging whitelist.
func IsMessageError ¶
IsMessageError reports whether consumption can continue after err.
func NewMessageError ¶
NewMessageError classifies a recoverable error associated with one consumed message without exposing its potentially sensitive cause in Error().
Types ¶
type Acknowledger ¶
type BasicDelivery ¶
type BasicDelivery struct {
// contains filtered or unexported fields
}
func NewDelivery ¶
func NewDelivery(envelope Envelope, info DeliveryInfo) BasicDelivery
func (BasicDelivery) Envelope ¶
func (d BasicDelivery) Envelope() Envelope
func (BasicDelivery) Info ¶
func (d BasicDelivery) Info() DeliveryInfo
type Capabilities ¶
type Capabilities struct {
Durability bool
Acknowledgement bool
CompetingConsumers bool
Ordering bool
Replay bool
RequestReply bool
Delay bool
Fanout bool
}
func (Capabilities) Supports ¶
func (c Capabilities) Supports(capability Capability) bool
func (Capabilities) Validate ¶
func (c Capabilities) Validate(required ...Capability) error
type Capability ¶
type Capability string
const ( CapabilityDurability Capability = "durability" CapabilityAcknowledgement Capability = "acknowledgement" CapabilityCompetingConsumers Capability = "competing_consumers" CapabilityOrdering Capability = "ordering" CapabilityReplay Capability = "replay" CapabilityRequestReply Capability = "request_reply" CapabilityDelay Capability = "delay" CapabilityFanout Capability = "fanout" )
func CapabilityForDisposition ¶
func CapabilityForDisposition(disposition Disposition) []Capability
type Codec ¶
type Codec interface {
Encode(context.Context, Envelope) ([]byte, error)
Decode(context.Context, []byte) (Envelope, error)
ContentType() string
}
Codec encodes and decodes complete transport envelopes.
type ConsumeDriver ¶
type CorrelationRegistry ¶
type CorrelationRegistry struct {
// contains filtered or unexported fields
}
func NewCorrelationRegistry ¶
func (*CorrelationRegistry) Deliver ¶
func (r *CorrelationRegistry) Deliver(envelope Envelope) bool
Deliver resolves exactly one matching waiter. False identifies late, duplicate, unknown, or mismatched replies; mismatches leave the real waiter active.
func (*CorrelationRegistry) Pending ¶
func (r *CorrelationRegistry) Pending() int
func (*CorrelationRegistry) Register ¶
func (r *CorrelationRegistry) Register(correlationID, expectedType string, deadline time.Time) (*ReplyWaiter, error)
Register must be called before publishing the corresponding request.
type Delivery ¶
type Delivery interface {
Envelope() Envelope
Info() DeliveryInfo
}
Delivery exposes clones so handlers cannot mutate driver-owned values.
type DeliveryInfo ¶
type DeliveryInfo struct {
Transport string
Destination string
DeliveryID string
Attempt int
ReceivedAt time.Time
Metadata map[string]string
}
func (DeliveryInfo) Clone ¶
func (i DeliveryInfo) Clone() DeliveryInfo
type Destination ¶
type Destination struct {
Name string
}
type Disposition ¶
type Disposition string
const ( DispositionComplete Disposition = "complete" DispositionRetry Disposition = "retry" DispositionReject Disposition = "reject" DispositionDeadLetter Disposition = "dead_letter" )
type Driver ¶
type Driver interface {
Capabilities() Capabilities
Start(context.Context) error
Ready() <-chan struct{}
Errors() <-chan error
Close(context.Context) error
}
Driver implementations must close Ready exactly once after their provider is usable. Start, Capabilities and Close must be safe for concurrent callers.
type DriverRegistry ¶
type DriverRegistry struct {
// contains filtered or unexported fields
}
DriverRegistry atomically publishes complete immutable driver snapshots.
func NewDriverRegistry ¶
func NewDriverRegistry(drivers map[string]Driver) (*DriverRegistry, error)
func (*DriverRegistry) All ¶
func (r *DriverRegistry) All() map[string]Driver
func (*DriverRegistry) Require ¶
func (r *DriverRegistry) Require(name string, required ...Capability) (Driver, error)
type Envelope ¶
type Envelope struct {
ID string `json:"id"`
Type string `json:"type"`
Kind Kind `json:"kind"`
SchemaVersion string `json:"schema_version"`
Payload []byte `json:"-"`
ContentType string `json:"content_type"`
Timestamp time.Time `json:"timestamp"`
CorrelationID string `json:"correlation_id,omitempty"`
CausationID string `json:"causation_id,omitempty"`
ReplyTo string `json:"reply_to,omitempty"`
Deadline time.Time `json:"deadline"`
Headers map[string]string `json:"headers,omitempty"`
}
Envelope is the transport-neutral message exchanged across driver boundaries. Use NewEnvelope or Clone before handing values to independently-owned code.
func NewEnvelope ¶
func NewEnvelope(id, messageType string, kind Kind, schemaVersion, contentType string, payload []byte, headers map[string]string) Envelope
NewEnvelope constructs an envelope and defensively copies mutable fields.
func (Envelope) ValidateWith ¶
func (e Envelope) ValidateWith(limits ValidationLimits) error
type HandleResult ¶
type HandleResult struct {
Disposition Disposition
RetryAfter time.Duration
Err error
}
func Complete ¶
func Complete() HandleResult
func DeadLetter ¶
func DeadLetter(err error) HandleResult
func InvokeHandler ¶
func InvokeHandler(ctx context.Context, handler Handler, delivery Delivery) (result HandleResult)
InvokeHandler contains untrusted handler panics at the delivery boundary. The panic value is deliberately excluded from the returned error because it may contain payload or credential data.
func Reject ¶
func Reject(err error) HandleResult
type Ingress ¶
type Ingress struct {
// contains filtered or unexported fields
}
func NewIngress ¶
func NewIngress(drivers *DriverRegistry, bindings []IngressBinding, options ...IngressOption) (*Ingress, error)
func (*Ingress) ReplaceBindings ¶
func (i *Ingress) ReplaceBindings(bindings []IngressBinding) error
type IngressBinding ¶
type IngressOption ¶
type IngressOption func(*Ingress)
func WithIngressObserver ¶
func WithIngressObserver(observer Observer) IngressOption
type JSONCodec ¶
type JSONCodec struct {
Limits ValidationLimits
MaxFrameBytes int
}
func NewJSONCodec ¶
func NewJSONCodec() JSONCodec
func (JSONCodec) ContentType ¶
type LifecycleState ¶
type LifecycleState string
const ( LifecycleNew LifecycleState = "new" LifecycleStarting LifecycleState = "starting" LifecycleReady LifecycleState = "ready" LifecycleClosing LifecycleState = "closing" LifecycleClosed LifecycleState = "closed" LifecycleFailed LifecycleState = "failed" )
type MessageError ¶
type MessageError struct {
Cause error
}
MessageError marks a per-message decode, policy, or handler failure. The subscription remains usable; lifecycle and provider errors are deliberately left unwrapped so callers can treat them as terminal.
func (*MessageError) Error ¶
func (e *MessageError) Error() string
func (*MessageError) Is ¶
func (e *MessageError) Is(target error) bool
func (*MessageError) Unwrap ¶
func (e *MessageError) Unwrap() error
type NackOptions ¶
type NackOptions struct {
Disposition Disposition
RetryAfter time.Duration
Reason string
}
type NopObserver ¶
type NopObserver struct{}
func (NopObserver) Observe ¶
func (NopObserver) Observe(context.Context, Observation)
type Observation ¶
type Observation struct {
Operation Operation
LogicalRoute string
Kind Kind
MessageType string
Transport string
Destination string
CorrelationID string
Attempt int
Outcome string
Latency time.Duration
Err error
}
Observation intentionally excludes payload and provider credentials.
type Observer ¶
type Observer interface {
Observe(context.Context, Observation)
}
type ObserverFunc ¶
type ObserverFunc func(context.Context, Observation)
func (ObserverFunc) Observe ¶
func (f ObserverFunc) Observe(ctx context.Context, observation Observation)
type PublishDriver ¶
type PublishOutcome ¶
type PublishOutcome string
const ( PublishAccepted PublishOutcome = "accepted" PublishRejected PublishOutcome = "rejected" PublishDefinitelyNotPublished PublishOutcome = "definitely_not_published" PublishAmbiguous PublishOutcome = "ambiguous" )
type PublishResult ¶
type PublishResult struct {
Outcome PublishOutcome
Transport string
Destination string
ProviderMessageID string
RecipientCount *int64
Metadata map[string]string
}
func (PublishResult) Clone ¶
func (r PublishResult) Clone() PublishResult
func (PublishResult) OutcomeError ¶
func (r PublishResult) OutcomeError() error
OutcomeError converts a non-accepted publish outcome into its stable error classification. Drivers may return both provider-specific errors and an outcome; routers use this method when a driver omits the corresponding error.
type Publisher ¶
type Publisher interface {
Publish(context.Context, Destination, Envelope) (PublishResult, error)
}
type ReplyWaiter ¶
type ReplyWaiter struct {
// contains filtered or unexported fields
}
func (*ReplyWaiter) Cancel ¶
func (w *ReplyWaiter) Cancel()
type RouteBinding ¶
type RouteBinding struct {
Driver string
Destination Destination
}
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router resolves logical routes against an immutable configuration generation.
func NewRouter ¶
func NewRouter(drivers *DriverRegistry, routes []Route, observer Observer) (*Router, error)
func (*Router) ReplaceRoutes ¶
type RoutingResult ¶
type RoutingResult struct {
Route string
Results []PublishResult
Mirrored int
}
type Subscription ¶
type TransportError ¶
type TransportError struct {
Class error
Transport string
Operation string
Temporary bool
Cause error
}
func (*TransportError) Error ¶
func (e *TransportError) Error() string
func (*TransportError) Is ¶
func (e *TransportError) Is(target error) bool
func (*TransportError) Unwrap ¶
func (e *TransportError) Unwrap() error
type ValidationLimits ¶
type ValidationLimits struct {
MaxPayloadBytes int
MaxHeaderCount int
MaxHeaderKeyBytes int
MaxHeaderValueBytes int
MaxMetadataBytes int
SupportedSchemas map[string]struct{}
}
ValidationLimits bounds data that is decoded or forwarded by the framework.
func DefaultValidationLimits ¶
func DefaultValidationLimits() ValidationLimits