Documentation
¶
Overview ¶
Package messenger provides typed commands, local queries, and events with explicit descriptors, GoBus dispatch, and transport-neutral one-way delivery contracts. Queries are process-local request/reply calls and never use the wire envelope or durable routes.
Index ¶
- Constants
- Variables
- func CanonicalizeEnvelope(data []byte) ([]byte, error)
- func ContextWithMetadata(ctx context.Context, metadata Metadata) context.Context
- func DecodeCommandPayload[T any](descriptor Command[T], data []byte) (T, error)
- func DecodeEventPayload[T any](descriptor Event[T], data []byte) (T, error)
- func EncodeCommandEnvelope[T any](descriptor Command[T], metadata Metadata, payload T) ([]byte, error)
- func EncodeEventEnvelope[T any](descriptor Event[T], metadata Metadata, payload T) ([]byte, error)
- func EnvelopeFingerprint(data []byte) [sha256.Size]byte
- func IsPermanent(err error) bool
- func MarshalEnvelope(metadata Metadata, payload []byte, encoding DataEncoding) ([]byte, error)
- func Permanent(err error) error
- func RetryAfter(err error, delay time.Duration) error
- func RetryDelay(err error) (time.Duration, bool)
- type Builder
- func (b *Builder) Build() (*Messenger, *Runtime, error)
- func (b *Builder) HandleCommand[T any](descriptor Command[T], handlerID string, handler Handler[T])
- func (b *Builder) HandleCommandFunc[T any](descriptor Command[T], handlerID string, handler PayloadHandler[T])
- func (b *Builder) HandleQuery[Q, R any](descriptor Query[Q, R], handlerID string, handler QueryHandler[Q, R])
- func (b *Builder) HandleQueryFunc[Q, R any](descriptor Query[Q, R], handlerID string, handler QueryPayloadHandler[Q, R])
- func (b *Builder) RouteCommand[T any](descriptor Command[T], route Route)
- func (b *Builder) RouteEvent[T any](descriptor Event[T], route Route)
- func (b *Builder) RouteQuery[Q, R any](descriptor Query[Q, R], route LocalQueryRoute)
- func (b *Builder) Subscribe[T any](descriptor Event[T], subscriptionID string, handler Handler[T])
- func (b *Builder) SubscribeFunc[T any](descriptor Event[T], subscriptionID string, handler PayloadHandler[T])
- func (b *Builder) Use(serviceID string, service Service)
- func (b *Builder) UseMiddleware(middlewares ...Middleware)
- type Codec
- type Command
- type ContextPropagator
- type DataEncoding
- type Delivery
- type DescriptorInfo
- type Envelope
- type Event
- type Handler
- type HandlerFunc
- type HandlerMiddleware
- type IDGenerator
- type Kind
- type LocalAsyncConfig
- type LocalAsyncRoute
- func (r *LocalAsyncRoute) BeginDrain()
- func (r *LocalAsyncRoute) Deliver(ctx context.Context, delivery Delivery) (Receipt, error)
- func (r *LocalAsyncRoute) ManagedService() (string, Service)
- func (r *LocalAsyncRoute) Name() string
- func (r *LocalAsyncRoute) Readiness(context.Context) error
- func (r *LocalAsyncRoute) Run(ctx context.Context) error
- func (r *LocalAsyncRoute) Shutdown(ctx context.Context) error
- type LocalQueryRoute
- type LocalSyncRoute
- type LogAttr
- type LogLevel
- type Logger
- type Manifest
- type ManifestDescriptor
- type Message
- type MessageID
- type Messenger
- func (m *Messenger) Manifest() Manifest
- func (m *Messenger) MarshalManifest() ([]byte, error)
- func (m *Messenger) Publish[T any](ctx context.Context, descriptor Event[T], payload T) (Receipt, error)
- func (m *Messenger) PublishMessage[T any](ctx context.Context, descriptor Event[T], outgoing Outgoing[T]) (Receipt, error)
- func (m *Messenger) Query[Q, R any](ctx context.Context, descriptor Query[Q, R], payload Q) (R, error)
- func (m *Messenger) Send[T any](ctx context.Context, descriptor Command[T], payload T) (Receipt, error)
- func (m *Messenger) SendMessage[T any](ctx context.Context, descriptor Command[T], outgoing Outgoing[T]) (Receipt, error)
- type Metadata
- type Middleware
- type Observation
- type Observer
- type Operation
- type Option
- type Outgoing
- type OutgoingMetadata
- type PayloadHandler
- type Publisher
- type Querier
- type Query
- type QueryHandler
- type QueryHandlerMiddleware
- type QueryPayloadHandler
- type Receipt
- type ReceiptState
- type Route
- type Runtime
- type Sender
- type Service
- type ServiceProvider
Examples ¶
Constants ¶
const ( // EnvelopeSpecVersion is the current native envelope contract. EnvelopeSpecVersion = "1.0" // DefaultMaxEnvelopeBytes is the default encoded envelope limit. DefaultMaxEnvelopeBytes = 1 << 20 // DefaultMaxHeaders is the default number of application headers. DefaultMaxHeaders = 64 // DefaultMaxHeaderBytes is the default aggregate application-header limit. DefaultMaxHeaderBytes = 16 << 10 )
const ManifestSpecVersion = "1.0"
ManifestSpecVersion is the current topology manifest contract.
Variables ¶
var ( // ErrInvalidDescriptor reports an invalid command, event, or query descriptor. ErrInvalidDescriptor = errors.New("messenger: invalid descriptor") // ErrInvalidMessage reports invalid outgoing metadata or envelope data. ErrInvalidMessage = errors.New("messenger: invalid message") // ErrDescriptorConflict reports two incompatible descriptors with one wire identity. ErrDescriptorConflict = errors.New("messenger: descriptor conflict") // ErrHandlerConflict reports a duplicate command handler or subscription ID. ErrHandlerConflict = errors.New("messenger: handler conflict") // ErrHandlerNotFound reports a missing required local handler. ErrHandlerNotFound = errors.New("messenger: handler not found") // ErrQueryResultMissing reports successful global middleware completion without a query result. ErrQueryResultMissing = errors.New("messenger: query result missing") // ErrRouteConflict reports more than one primary route for a descriptor. ErrRouteConflict = errors.New("messenger: route conflict") // ErrRouteNotFound reports that a descriptor has no outbound route. ErrRouteNotFound = errors.New("messenger: route not found") // ErrServiceConflict reports a duplicate managed service ID. ErrServiceConflict = errors.New("messenger: service conflict") // ErrRuntimeNotRunning reports an operation that requires a running runtime. ErrRuntimeNotRunning = errors.New("messenger: runtime not running") // ErrRuntimeRunning reports a second concurrent call to Runtime.Run. ErrRuntimeRunning = errors.New("messenger: runtime already running") // ErrRuntimeClosed reports use after a runtime has shut down. ErrRuntimeClosed = errors.New("messenger: runtime closed") // ErrEnvelopeTooLarge reports an envelope beyond the configured wire limit. ErrEnvelopeTooLarge = errors.New("messenger: envelope too large") )
Functions ¶
func CanonicalizeEnvelope ¶
CanonicalizeEnvelope parses and re-encodes an envelope using the native deterministic field order. Delivery metadata is never included.
func ContextWithMetadata ¶
ContextWithMetadata installs immutable message lineage for an adapter or terminal handler entering the typed messenger boundary.
func DecodeCommandPayload ¶
DecodeCommandPayload decodes codec bytes without an envelope.
func DecodeEventPayload ¶
DecodeEventPayload decodes codec bytes without an envelope.
func EncodeCommandEnvelope ¶
func EncodeCommandEnvelope[T any](descriptor Command[T], metadata Metadata, payload T) ([]byte, error)
EncodeCommandEnvelope encodes a typed command with already resolved metadata.
func EncodeEventEnvelope ¶
EncodeEventEnvelope encodes a typed event with already resolved metadata.
func EnvelopeFingerprint ¶
EnvelopeFingerprint returns SHA-256 over canonical encoded envelope bytes.
func IsPermanent ¶
IsPermanent reports whether err contains a Permanent marker.
func MarshalEnvelope ¶
func MarshalEnvelope(metadata Metadata, payload []byte, encoding DataEncoding) ([]byte, error)
MarshalEnvelope validates and encodes an envelope with a codec payload.
func RetryAfter ¶
RetryAfter asks a durable transport to retry after an exact positive delay.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder declares immutable descriptors, handlers, routes, and managed services. It is not safe for concurrent mutation.
func NewBuilder ¶
NewBuilder constructs an empty messenger builder.
func (*Builder) HandleCommand ¶
HandleCommand registers the one local handler for a command descriptor. Validation errors are returned by Build.
func (*Builder) HandleCommandFunc ¶
func (b *Builder) HandleCommandFunc[T any]( descriptor Command[T], handlerID string, handler PayloadHandler[T], )
HandleCommandFunc registers a payload-only command handler.
func (*Builder) HandleQuery ¶
func (b *Builder) HandleQuery[Q, R any]( descriptor Query[Q, R], handlerID string, handler QueryHandler[Q, R], )
HandleQuery registers the one local handler for a query descriptor. Validation errors are returned by Build.
func (*Builder) HandleQueryFunc ¶
func (b *Builder) HandleQueryFunc[Q, R any]( descriptor Query[Q, R], handlerID string, handler QueryPayloadHandler[Q, R], )
HandleQueryFunc registers a payload-only local query handler.
func (*Builder) RouteCommand ¶
RouteCommand sets the command's one primary outbound route.
func (*Builder) RouteEvent ¶
RouteEvent sets the event's one primary outbound route.
func (*Builder) RouteQuery ¶
func (b *Builder) RouteQuery[Q, R any](descriptor Query[Q, R], route LocalQueryRoute)
RouteQuery sets the query's required local request/reply route.
func (*Builder) Subscribe ¶
Subscribe appends a named local event subscription. Validation errors are returned by Build.
func (*Builder) SubscribeFunc ¶
func (b *Builder) SubscribeFunc[T any]( descriptor Event[T], subscriptionID string, handler PayloadHandler[T], )
SubscribeFunc appends a payload-only event subscription.
func (*Builder) UseMiddleware ¶
func (b *Builder) UseMiddleware(middlewares ...Middleware)
UseMiddleware appends global handler middleware. Validation errors are returned by Build.
type Codec ¶
type Codec[T any] interface { Encode(value T) ([]byte, error) Decode(data []byte) (T, error) ContentType() string Encoding() DataEncoding }
Codec encodes and decodes one descriptor payload type.
type Command ¶
type Command[T any] struct { // contains filtered or unexported fields }
Command is an immutable typed command descriptor.
func MustCommand ¶
MustCommand constructs a command descriptor and panics when its declaration is invalid.
func NewCommand ¶
NewCommand constructs a command descriptor.
func (Command[T]) Info ¶
func (d Command[T]) Info() DescriptorInfo
Info returns a copy of the command's wire identity.
func (Command[T]) WithSchema ¶
WithSchema returns a command descriptor with an explicit schema URI.
type ContextPropagator ¶
type ContextPropagator interface {
Inject(ctx context.Context, carrier map[string]string)
Extract(ctx context.Context, carrier map[string]string) context.Context
}
ContextPropagator injects and extracts distributed context through immutable message headers.
func NoopContextPropagator ¶
func NoopContextPropagator() ContextPropagator
NoopContextPropagator returns a propagator that leaves contexts and carriers unchanged.
type DataEncoding ¶
type DataEncoding uint8
DataEncoding selects how encoded payload bytes appear in envelope JSON.
const ( // DataJSON stores codec output directly in the envelope data field. DataJSON DataEncoding = iota + 1 // DataText stores codec output as a JSON string in the envelope data field. DataText // DataBinary stores codec output in the envelope dataBase64 field. DataBinary )
func (DataEncoding) MarshalJSON ¶
func (e DataEncoding) MarshalJSON() ([]byte, error)
MarshalJSON encodes a data encoding as its stable wire name.
func (DataEncoding) String ¶
func (e DataEncoding) String() string
String returns the stable wire name of the data encoding.
func (*DataEncoding) UnmarshalJSON ¶
func (e *DataEncoding) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a stable data-encoding wire name.
type Delivery ¶
type Delivery interface {
Metadata() Metadata
HandlerCount() int
MarshalEnvelope() ([]byte, error)
Fingerprint() ([sha256.Size]byte, error)
Invoke(ctx context.Context) error
}
Delivery is the transport-neutral route input. MarshalEnvelope is lazy, so local routes do not serialize payloads. Invoke is intended for local and terminal durable adapters.
type DescriptorInfo ¶
type DescriptorInfo struct {
Kind Kind `json:"kind"`
Name string `json:"name"`
SchemaVersion int `json:"schemaVersion"`
ContentType string `json:"contentType"`
DataEncoding DataEncoding `json:"dataEncoding"`
Schema string `json:"schema,omitempty"`
}
DescriptorInfo is the transport-neutral public identity of a descriptor.
type Envelope ¶
type Envelope struct {
SpecVersion string `json:"specVersion"`
ID MessageID `json:"id"`
Kind Kind `json:"kind"`
Name string `json:"name"`
SchemaVersion int `json:"schemaVersion"`
Source string `json:"source"`
Subject string `json:"subject,omitempty"`
Time time.Time `json:"time"`
CorrelationID MessageID `json:"correlationId"`
CausationID MessageID `json:"causationId,omitzero"`
Key string `json:"key,omitempty"`
ContentType string `json:"contentType"`
DataEncoding DataEncoding `json:"dataEncoding"`
Schema string `json:"schema,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
NotBefore time.Time `json:"notBefore,omitzero"`
ExpiresAt time.Time `json:"expiresAt,omitzero"`
Data json.RawMessage `json:"data,omitempty"`
DataBase64 *string `json:"dataBase64,omitempty"`
}
Envelope is the canonical native wire representation.
func UnmarshalEnvelope ¶
UnmarshalEnvelope parses and validates a native envelope.
type Event ¶
type Event[T any] struct { // contains filtered or unexported fields }
Event is an immutable typed event descriptor.
func MustEvent ¶
MustEvent constructs an event descriptor and panics when its declaration is invalid.
func (Event[T]) Info ¶
func (d Event[T]) Info() DescriptorInfo
Info returns a copy of the event's wire identity.
func (Event[T]) WithSchema ¶
WithSchema returns an event descriptor with an explicit schema URI.
type Handler ¶
Handler processes one typed message.
func ChainHandler ¶
func ChainHandler[T any](handler Handler[T], middlewares ...HandlerMiddleware[T]) Handler[T]
ChainHandler applies typed middleware with the first item outermost. It returns nil when handler, a middleware, or a middleware result is nil so the receiving Builder or durable consumer can reject the invalid chain.
func HandlePayload ¶
func HandlePayload[T any](handler PayloadHandler[T]) Handler[T]
HandlePayload adapts a payload-only handler to the primary Handler contract.
type HandlerFunc ¶
HandlerFunc is the transport-neutral terminal handler shape used by global middleware.
type HandlerMiddleware ¶
HandlerMiddleware wraps a typed handler.
type IDGenerator ¶
IDGenerator creates stable message identities.
func UUIDv7Generator ¶
func UUIDv7Generator() IDGenerator
UUIDv7Generator returns the default cryptographically random UUIDv7 generator.
type LocalAsyncConfig ¶
type LocalAsyncConfig struct {
Capacity int
Workers int
// DetachExecution is retained for source compatibility. Accepted one-way
// jobs always detach execution from the caller's cancellation and deadline.
// Query calls always retain the caller context for execution and waiting.
//
// Deprecated: caller context controls admission only.
DetachExecution bool
}
LocalAsyncConfig bounds local asynchronous admission and execution.
type LocalAsyncRoute ¶
type LocalAsyncRoute struct {
// contains filtered or unexported fields
}
LocalAsyncRoute admits handler calls to a bounded GoBus async runtime.
func NewLocalAsyncRoute ¶
func NewLocalAsyncRoute(name string, config LocalAsyncConfig) (*LocalAsyncRoute, error)
NewLocalAsyncRoute constructs a named bounded local asynchronous route.
func (*LocalAsyncRoute) BeginDrain ¶
func (r *LocalAsyncRoute) BeginDrain()
BeginDrain rejects new work and drains accepted jobs.
func (*LocalAsyncRoute) Deliver ¶
Deliver implements Route and reports admission, not handler completion.
func (*LocalAsyncRoute) ManagedService ¶
func (r *LocalAsyncRoute) ManagedService() (string, Service)
ManagedService exposes this route to Builder runtime aggregation.
func (*LocalAsyncRoute) Readiness ¶
func (r *LocalAsyncRoute) Readiness(context.Context) error
Readiness verifies that this route is accepting work.
type LocalQueryRoute ¶
type LocalQueryRoute interface {
Name() string
// contains filtered or unexported methods
}
LocalQueryRoute is the sealed local request/reply route contract. The built-in LocalSyncRoute and LocalAsyncRoute are its only implementations.
type LocalSyncRoute ¶
type LocalSyncRoute struct {
// contains filtered or unexported fields
}
LocalSyncRoute executes handlers synchronously through a private GoBus instance.
func NewLocalSyncRoute ¶
func NewLocalSyncRoute() *LocalSyncRoute
NewLocalSyncRoute constructs a local synchronous route.
type LogLevel ¶
type LogLevel uint8
LogLevel is the transport-neutral severity understood by Logger.
type Logger ¶
type Logger interface {
Log(ctx context.Context, level LogLevel, message string, attrs ...LogAttr)
}
Logger is the minimal structured logging contract used by GoMessenger. Implementations must not retain ctx and should return quickly.
type Manifest ¶
type Manifest struct {
SpecVersion string `json:"specVersion"`
Source string `json:"source"`
Descriptors []ManifestDescriptor `json:"descriptors"`
Services []string `json:"services,omitempty"`
}
Manifest is a deterministic, secret-free description of runtime topology.
type ManifestDescriptor ¶
type ManifestDescriptor struct {
DescriptorInfo
Route string `json:"route,omitempty"`
HandlerIDs []string `json:"handlerIds,omitempty"`
}
ManifestDescriptor describes one typed descriptor and its static route.
type Message ¶
Message is the typed value passed to a handler.
func DecodeCommand ¶
DecodeCommand decodes and verifies a native command envelope.
type MessageID ¶
type MessageID [16]byte
MessageID is a UUID-compatible 128-bit message identity.
func ParseMessageID ¶
ParseMessageID parses the canonical UUID text form.
func (MessageID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (MessageID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*MessageID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*MessageID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger sends commands, executes local queries, and publishes events through immutable descriptor bindings.
func (*Messenger) MarshalManifest ¶
MarshalManifest returns deterministic indented JSON suitable for gomessengerctl.
func (*Messenger) Publish ¶
func (m *Messenger) Publish[T any](ctx context.Context, descriptor Event[T], payload T) (Receipt, error)
Publish publishes an event with generated metadata.
func (*Messenger) PublishMessage ¶
func (m *Messenger) PublishMessage[T any]( ctx context.Context, descriptor Event[T], outgoing Outgoing[T], ) (Receipt, error)
PublishMessage publishes an event with explicit optional metadata.
func (*Messenger) Query ¶
func (m *Messenger) Query[Q, R any]( ctx context.Context, descriptor Query[Q, R], payload Q, ) (R, error)
Query executes a typed local request/reply call through its configured route.
Example ¶
package main
import (
"context"
"fmt"
messenger "github.com/assurrussa/gomessenger"
)
func main() {
type findArticle struct{ ID int64 }
type articleView struct {
ID int64
Title string
}
find := messenger.MustQuery[findArticle, articleView]("article.find", 1, messenger.JSON[findArticle]())
builder := messenger.NewBuilder(messenger.WithSource("urn:service:catalog"))
builder.HandleQueryFunc(find, "article-reader", func(_ context.Context, query findArticle) (articleView, error) {
return articleView{ID: query.ID, Title: "CQRS in Go"}, nil
})
builder.RouteQuery(find, messenger.NewLocalSyncRoute())
bus, _, err := builder.Build()
if err != nil {
panic(err)
}
reader := messenger.BindQuerier(bus, find)
article, err := reader.Query(context.Background(), findArticle{ID: 42})
if err != nil {
panic(err)
}
fmt.Println(article.ID, article.Title)
}
Output: 42 CQRS in Go
func (*Messenger) Send ¶
func (m *Messenger) Send[T any](ctx context.Context, descriptor Command[T], payload T) (Receipt, error)
Send sends a command with generated metadata.
Example ¶
package main
import (
"context"
"fmt"
messenger "github.com/assurrussa/gomessenger"
)
func main() {
type resizeMedia struct {
JobID int64 `json:"jobId"`
}
resize := messenger.MustCommand("media.resize", 1, messenger.JSON[resizeMedia]())
builder := messenger.NewBuilder(messenger.WithSource("urn:service:media-resizer"))
builder.HandleCommandFunc(resize, "media-worker", func(_ context.Context, payload resizeMedia) error {
fmt.Println("handler", payload.JobID)
return nil
})
builder.RouteCommand(resize, messenger.NewLocalSyncRoute())
bus, _, err := builder.Build()
if err != nil {
panic(err)
}
resizeSender := messenger.BindSender(bus, resize)
receipt, err := resizeSender.Send(context.Background(), resizeMedia{JobID: 42})
if err != nil {
panic(err)
}
fmt.Println(receipt.State)
}
Output: handler 42 completed
type Metadata ¶
type Metadata struct {
ID MessageID
Kind Kind
Name string
SchemaVersion int
Source string
Subject string
Time time.Time
CorrelationID MessageID
CausationID MessageID
Key string
ContentType string
Schema string
Headers map[string]string
NotBefore time.Time
ExpiresAt time.Time
}
Metadata is canonical message metadata independent of a transport attempt.
type Middleware ¶
type Middleware func( ctx context.Context, metadata Metadata, handlerID string, next HandlerFunc, ) error
Middleware wraps one local query/command/event or durable handler. The first registered middleware is the outermost wrapper and may short-circuit by not calling next.
type Observation ¶
type Observation struct {
Operation Operation
MessageID MessageID
Kind Kind
Name string
SchemaVersion int
Route string
HandlerID string
ConsumerID string
ServiceID string
Attempt uint64
Duplicate bool
RetryDelay time.Duration
State ReceiptState
StartedAt time.Time
Duration time.Duration
Err error
}
Observation contains bounded operational data. Observers decide which fields are safe for low-cardinality metric labels.
type Observer ¶
type Observer interface {
Observe(ctx context.Context, observation Observation)
}
Observer receives messaging lifecycle observations. Implementations must not retain ctx and should return quickly.
func NewLoggingObserver ¶
NewLoggingObserver reports observations through logger. Successful operations use Debug and failed operations use Error. A nil logger creates a no-op observer.
type Operation ¶
type Operation string
Operation identifies an observable messaging boundary.
const ( // OperationDeliver covers outbound route delivery. OperationDeliver Operation = "deliver" // OperationHandle covers local or durable handler execution. OperationHandle Operation = "handle" // OperationQuery covers a complete local request/reply call. OperationQuery Operation = "query" // OperationService covers managed service completion. OperationService Operation = "service" )
type Option ¶
type Option func(*Builder)
Option configures a Builder.
func WithContextPropagator ¶
func WithContextPropagator(propagator ContextPropagator) Option
WithContextPropagator sets distributed-context injection for outgoing metadata. The default propagator is a no-op.
func WithIDGenerator ¶
func WithIDGenerator(generator IDGenerator) Option
WithIDGenerator overrides UUIDv7 generation, primarily for deterministic tests.
func WithLogger ¶
WithLogger sets the core structured logger. The default logger is a no-op.
func WithObserver ¶
WithObserver appends a lifecycle observer.
func WithSource ¶
WithSource sets the required stable producer identity.
type Outgoing ¶
type Outgoing[T any] struct { Payload T Metadata OutgoingMetadata }
Outgoing combines a typed payload with optional explicit metadata.
type OutgoingMetadata ¶
type OutgoingMetadata struct {
ID MessageID
Subject string
Time time.Time
CorrelationID MessageID
CausationID MessageID
Key string
Headers map[string]string
NotBefore time.Time
ExpiresAt time.Time
}
OutgoingMetadata customizes metadata generated for a new outgoing message. Source, kind, name, schema version, content type, and schema come from the builder and descriptor and cannot be overridden per call.
type PayloadHandler ¶
PayloadHandler processes only the payload and ignores message metadata.
type Publisher ¶
type Publisher[T any] interface { Publish(ctx context.Context, payload T) (Receipt, error) PublishMessage(ctx context.Context, outgoing Outgoing[T]) (Receipt, error) }
Publisher is the ordinary generic DI interface for a bound event descriptor.
type Query ¶
type Query[Q, R any] struct { // contains filtered or unexported fields }
Query is an immutable typed local query descriptor. Its codec describes the request Q only; R is a compile-time result identity and is never serialized.
func MustQuery ¶
MustQuery constructs a typed local query descriptor and panics when its declaration is invalid.
func (Query[Q, R]) Info ¶
func (d Query[Q, R]) Info() DescriptorInfo
Info returns a copy of the query request identity.
func (Query[Q, R]) WithSchema ¶
WithSchema returns a query descriptor with an explicit request schema URI.
type QueryHandler ¶
QueryHandler processes one typed query and returns its typed result.
func ChainQueryHandler ¶
func ChainQueryHandler[Q, R any]( handler QueryHandler[Q, R], middlewares ...QueryHandlerMiddleware[Q, R], ) QueryHandler[Q, R]
ChainQueryHandler applies typed query middleware with the first item outermost. It returns nil when the chain is invalid.
func HandleQueryPayload ¶
func HandleQueryPayload[Q, R any](handler QueryPayloadHandler[Q, R]) QueryHandler[Q, R]
HandleQueryPayload adapts a payload-only query handler to QueryHandler.
type QueryHandlerMiddleware ¶
type QueryHandlerMiddleware[Q, R any] func(QueryHandler[Q, R]) QueryHandler[Q, R]
QueryHandlerMiddleware wraps a typed query handler and may return a cached or synthetic result without invoking the wrapped handler.
type QueryPayloadHandler ¶
QueryPayloadHandler processes only a query payload and returns its typed result.
type Receipt ¶
type Receipt struct {
MessageID MessageID `json:"messageId"`
Route string `json:"route"`
State ReceiptState `json:"state"`
At time.Time `json:"at"`
}
Receipt describes the guarantee reached by one primary route.
type ReceiptState ¶
type ReceiptState string
ReceiptState describes what a successful route call has guaranteed.
const ( // ReceiptCompleted means local synchronous handlers completed. ReceiptCompleted ReceiptState = "completed" // ReceiptAccepted means bounded in-process async admission succeeded. ReceiptAccepted ReceiptState = "accepted" // ReceiptStaged means an outbox write succeeded in the current transaction. ReceiptStaged ReceiptState = "staged" // ReceiptBrokerConfirmed means the broker confirmed persistence. ReceiptBrokerConfirmed ReceiptState = "broker_confirmed" // ReceiptNoop means a local event had no subscribers. ReceiptNoop ReceiptState = "noop" )
type Route ¶
type Route interface {
Name() string
Deliver(ctx context.Context, delivery Delivery) (Receipt, error)
}
Route is one static primary delivery route.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime supervises the services declared on one immutable Builder. It never restarts a service automatically.
func (*Runtime) BeginDrain ¶
func (r *Runtime) BeginDrain()
BeginDrain marks the runtime unready and asks every service to stop admission.
type Sender ¶
type Sender[T any] interface { Send(ctx context.Context, payload T) (Receipt, error) SendMessage(ctx context.Context, outgoing Outgoing[T]) (Receipt, error) }
Sender is the ordinary generic DI interface for a bound command descriptor.
type Service ¶
type Service interface {
Run(ctx context.Context) error
Readiness(ctx context.Context) error
BeginDrain()
Shutdown(ctx context.Context) error
}
Service is a host-supervised managed consumer or worker lifecycle.
type ServiceProvider ¶
ServiceProvider lets a route contribute one managed service to Builder.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
inbox
module
|
|
|
kafka
module
|
|
|
nats
module
|
|
|
outbox
module
|
|
|
observability
module
|
|
|
tools
|
|
|
gomessengerctl
module
|