Documentation
¶
Overview ¶
Package amqp implements the backend contract of gitlab.com/phpboyscout/go/messaging over AMQP 1.0, through Azure/go-amqp, generically: nothing broker-specific in the module's spine, and what the protocol cannot say asked through a Management seam the constructor requires. Apache ActiveMQ Artemis is the first target, with a Management that speaks the broker's management address over the same connection.
At-least-once attaches to an operator-created durable multicast queue named by the durable name on the address translated from the pattern, and verifies it through Management at attach; at-most-once attaches with a volatile source terminus and takes the queue the broker gives the link. The attempt is delivery-count plus one; the lease is the consumer's own; a publish is durable and waits for the broker's disposition.
Settings.Format writes what the backend publishes, CloudEvents binary for the AMQP binding when unset, and Settings.Reads is the chain it reads with, binary then structured when unset. String application properties no format takes reach a handler as Delivery.Foreign (messaging spec 0014).
Specified by https://gitlab.com/phpboyscout/go/messaging/-/wikis/specs/0008-the-amqp-backend
Index ¶
- Variables
- func New(ctx context.Context, s Settings, management Management) (messaging.Backend, error)
- type Artemis
- func (a Artemis) Create(ctx context.Context, sess *goamqp.Session, spec QueueSpec) error
- func (a Artemis) Delete(ctx context.Context, sess *goamqp.Session, _, queue string) error
- func (a Artemis) Describe(ctx context.Context, sess *goamqp.Session, address, queue string) (QueueInfo, error)
- func (Artemis) Features(ctx context.Context, sess *goamqp.Session) (Features, error)
- func (a Artemis) Routes(ctx context.Context, sess *goamqp.Session, address string) (bool, error)
- type ByName
- type Features
- type Management
- type QueueInfo
- type QueueSpec
- type Settings
- type Topology
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.NewSentinel("messaging_amqp.closed", "messaging-amqp: the session is closed")
ErrClosed is returned by Publish and Subscribe after Close: the message went nowhere, or the source would outlive its session, and a caller must know.
var ErrManagementRefused = errors.NewSentinel("messaging_amqp.management_refused", "messaging-amqp: the broker refused the management request")
ErrManagementRefused is a management request the broker answered with a failure that is not "no such object".
var ErrNoQueue = errors.NewSentinel("messaging_amqp.no_queue",
"messaging-amqp: the queue this subscription consumes does not exist; a bus attaches to a queue and never creates one")
ErrNoQueue is returned by Subscribe when the at-least-once queue a subscription names does not exist: the bus binds, and never creates (0005 D9, 0008 D3).
var ErrNotFound = errors.NewSentinel("messaging_amqp.not_found", "messaging-amqp: the broker has no such object")
ErrNotFound is Management's answer for a queue or address that does not exist.
var ErrUnrouted = errors.NewSentinel("messaging_amqp.unrouted",
"messaging-amqp: no queue on the broker receives from this subject's address; a publish to it would be accepted and kept by nobody")
ErrUnrouted is returned by Publish when nothing on the broker would receive a message on the subject's address: accepted and gone (0008 D11).
Functions ¶
func New ¶
New is the AMQP 1.0 backend (0008 D1, D6): one protocol, generic, with the Management it requires. It dials once to read the broker's Features, so the capabilities it declares are the broker's configuration and constant thereafter; a Management is required, because without one the backend could only guess.
Types ¶
type Artemis ¶
type Artemis struct{}
Artemis is the Management for Apache ActiveMQ Artemis (0008 D1, OQ1): it speaks the broker's management address over the same connection — attribute reads and operation invocations as messages to activemq.management with a dynamic reply address — and needs 2.44.0 or later. No second endpoint, no HTTP.
func (Artemis) Describe ¶
func (a Artemis) Describe(ctx context.Context, sess *goamqp.Session, address, queue string) (QueueInfo, error)
Describe reads the queue's own attributes and its address's settings.
func (Artemis) Features ¶
Features reads the broker-global settings the capabilities depend on (0008 D6, D8, D11). An attribute the broker does not expose reads as false: a feature that cannot be verified is not declared.
type Features ¶
type Features struct {
// PersistsDeliveryCount says the delivery count survives a restart with
// the count intact. On Artemis, only with the broker-global setting on.
PersistsDeliveryCount bool
// Persists says a durable message routed to a durable queue is on disk
// before its disposition: persistence on, journal sync on.
Persists bool
// Deduplicates says the broker keeps a duplicate-id cache the sender can
// key.
Deduplicates bool
// DeadLetters says an exhausted or rejected message goes somewhere, not
// nowhere, where the address is configured for it.
DeadLetters bool
}
Features is what a broker offers by configuration (0008 D1): known at construction, constant thereafter, and the source of every capability this backend declares rather than assumes.
type Management ¶
type Management interface {
// Features is what the broker offers by configuration.
Features(ctx context.Context, sess *goamqp.Session) (Features, error)
// Describe reports a queue on an address as the broker holds it.
// ErrNotFound if it does not exist.
Describe(ctx context.Context, sess *goamqp.Session, address, queue string) (QueueInfo, error)
// Routes says whether a publish to the address reaches any queue: one on
// the address itself, or one on a wildcard address that matches it. A
// publish that reaches none is accepted and gone (0008 D11).
Routes(ctx context.Context, sess *goamqp.Session, address string) (bool, error)
// Create makes a queue the backend owns; Delete removes one it owns.
Create(ctx context.Context, sess *goamqp.Session, spec QueueSpec) error
Delete(ctx context.Context, sess *goamqp.Session, address, queue string) error
}
Management is what the module cannot learn over the protocol, asked through the broker's own way of saying it (0008 D1). Every method takes the session so a Management can speak over the same connection.
type QueueInfo ¶
type QueueInfo struct {
Address string
RoutingType string // "MULTICAST" or "ANYCAST"
Durable bool
Filter string
// From the address's settings.
MaxDeliveryAttempts int
DeadLetterAddress string
DeadLetterHasQueue bool
}
QueueInfo is a queue as the broker holds it (0008 D3).
type Settings ¶
type Settings struct {
// URL is the AMQP 1.0 endpoint, amqp:// or amqps://.
URL string
// Username and Password are SASL PLAIN credentials; both empty means
// anonymous.
Username string
Password string
// DefaultAckWait is the lease when a subscription asks for none. Zero
// means thirty seconds (0008 D9): the protocol has no default of its own.
DefaultAckWait time.Duration
// Logger receives what the backend cannot return. Nil discards.
Logger *slog.Logger
// Topology resolves the queue an at-least-once subscription attaches to.
// Nil means the durable name is the queue's name (0008 D3). An operator's
// tool may create on resolve; a test fixture is one.
Topology Topology
// Format writes every event this backend publishes. Unset, it is
// CloudEvents binary for the AMQP binding (0014 D4, D6).
Format envelope.Format
// Reads is the chain a received message is read with, strictly: one
// format must claim it. Unset, it is binary for the AMQP binding, then
// structured.
Reads []envelope.Format
}
Settings is what the backend is built from (0008 D1, D2).
type Topology ¶
type Topology interface {
// Queue is the queue's name on the pattern's address. The session is
// passed so an operator's tool can use Management over the same
// connection.
Queue(ctx context.Context, sess *goamqp.Session, address string, spec messaging.SourceSpec) (string, error)
}
Topology is the operator's answer to which queue an at-least-once subscription attaches to (0008 D3). The module verifies and never creates.