Documentation
¶
Overview ¶
Package messaging builds the message publisher and consumer from config: the in-process memory broker (the default), SQS, or Redis Pub/Sub. Every publish runs through the client tier (Decorate); the SQS and Redis consumers observe each handle. The concrete backends live in the memory/, sqs/ and redis/ subpackages.
Index ¶
- Constants
- func Decorate(base interfaces.MessagePublisher, decs decorate.Decorations, name string, ...) (interfaces.MessagePublisher, error)
- func NewConsumerFromConfig(ctx context.Context, cfg Config, deps Deps) (interfaces.MessageConsumer, error)
- func NewFromConfig(ctx context.Context, cfg Config, deps Deps) (interfaces.MessagePublisher, error)
- type Config
- type Deps
- type Receive
Constants ¶
const ( // KindMemory delivers through an in-process broker (the default). KindMemory client.Kind = "memory" // KindSQS publishes to and consumes from SQS queues (one per topic). KindSQS client.Kind = "sqs" // KindRedis broadcasts over Redis Pub/Sub (at-most-once). KindRedis client.Kind = "redis" )
Variables ¶
This section is empty.
Functions ¶
func Decorate ¶ added in v0.0.7
func Decorate( base interfaces.MessagePublisher, decs decorate.Decorations, name string, opts ...client.Option, ) (interfaces.MessagePublisher, error)
Decorate runs every publish of base through the client tier as the client named name, each as the operation named by its topic in a producer span. A publish is retried only when deps carries a Retrier: a re-sent message is a duplicate an at-least-once consumer accepts. The topic is the operation, so the config tunes the publisher as a whole; Kinds passes client.Producer in opts for the producer spans.
func NewConsumerFromConfig ¶ added in v0.0.7
func NewConsumerFromConfig( ctx context.Context, cfg Config, deps Deps, ) (interfaces.MessageConsumer, error)
NewConsumerFromConfig builds the consumer cfg.Kind selects; each backend runs every handler call through the handler tier, decorated as the client "<name>.handler" (observed and bounded, never retried or broken). An unknown kind is CodeInvalidInput.
func NewFromConfig ¶
func NewFromConfig( ctx context.Context, cfg Config, deps Deps, ) (interfaces.MessagePublisher, error)
NewFromConfig builds the publisher cfg.Kind selects and runs it through the client tier. ctx bounds the SQS kind's AWS config load; the other kinds do no I/O. Redis publishes are never retried: PUBLISH is at-most-once, so a retry could double-broadcast. An unknown kind is CodeInvalidInput.
Types ¶
type Config ¶
type Config struct {
// Kind selects the backend; empty means KindMemory.
Kind client.Kind `yaml:"kind" mapstructure:"kind"`
// SQS is KindSQS's connection: region, endpoint and credentials (env-bound).
SQS infra.SQSConfig `yaml:"sqs" mapstructure:"sqs"`
// Name labels the client in decoration overrides, metrics, spans and logs; empty
// uses the family name ("messaging").
Name string `yaml:"name" mapstructure:"name"`
// Receive tunes the KindSQS consumer's long poll and failed-message backoff.
Receive Receive `yaml:"receive" mapstructure:"receive"`
}
Config selects and tunes the messaging backend.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the memory kind in us-east-1.
type Deps ¶ added in v0.0.7
type Deps struct {
// Decorations decorates the client from the decoration config (decoration.clients)
// and supplies its observability.
decorate.Decorations
// Redis is the shared go-redis client KindRedis requires.
Redis *goredis.Client
// Broker connects a KindMemory publisher and consumer; nil gives each its own.
Broker *memory.Broker
// SQSAPI replaces the SQS SDK client KindSQS builds from Config.SQS.
SQSAPI sqs.API
// Ready gates every SQS receive: while it errors the consumer backs off.
Ready func(ctx context.Context) error
}
Deps carries the messaging runtime collaborators.
type Receive ¶ added in v0.0.7
type Receive struct {
// NackDelay, when Max is positive, hides a message whose handler failed for a
// jittered delay before redelivery.
NackDelay sqs.NackDelay `yaml:"nack_delay" mapstructure:"nack_delay"`
// BaseBackoff is the initial wait after a failed receive; 0 uses the default.
BaseBackoff time.Duration `yaml:"base_backoff" mapstructure:"base_backoff"`
// WaitTimeSeconds is the long-poll wait per receive, 0 to 20; 0 uses the default.
WaitTimeSeconds int32 `yaml:"wait_time_seconds" mapstructure:"wait_time_seconds"`
}
Receive tunes how a consumer receives (the poll and backoff fields are KindSQS's).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package memory provides an in-process messaging backend for no-infra builds and tests.
|
Package memory provides an in-process messaging backend for no-infra builds and tests. |
|
Package redis provides a Redis Pub/Sub messaging integration (publisher + subscriber) implementing the core MessagePublisher / MessageConsumer contracts over PUBLISH / SUBSCRIBE / PSUBSCRIBE.
|
Package redis provides a Redis Pub/Sub messaging integration (publisher + subscriber) implementing the core MessagePublisher / MessageConsumer contracts over PUBLISH / SUBSCRIBE / PSUBSCRIBE. |
|
Package sqs provides an AWS-SDK-backed SQS messaging integration (publisher + subscriber) usable against real AWS SQS and against ElasticMQ for local dev.
|
Package sqs provides an AWS-SDK-backed SQS messaging integration (publisher + subscriber) usable against real AWS SQS and against ElasticMQ for local dev. |