Documentation
¶
Overview ¶
Package rabbitmq implements the backend contract of gitlab.com/phpboyscout/go/messaging over RabbitMQ: AMQP 0-9-1 for the wire, through rabbitmq/amqp091-go, and the HTTP management API for every fact about a queue the wire cannot return.
At-least-once consumes an operator-created quorum queue named by the durable name, bound to the operator's topic exchange with the subscription's pattern; the backend verifies the queue's type, its effective delivery limit, its dead-letter configuration and its bindings through management, and refuses naming what it found. At-most-once builds its own transient topology per source and acknowledges each message as it hands it over. The attempt is the broker's x-delivery-count plus one; the lease is the consumer's own; a publish is confirmed, persistent and mandatory.
A publish is never deduplicated. RabbitMQ has no publisher-side identity, so a publish retried after an ambiguous failure — a timeout, a lost connection between the broker writing the message and the confirm arriving — is stored twice and delivered twice. Consumers on this backend must be idempotent, which JetStream and SQS FIFO would otherwise have hidden.
Settings.Format writes what the backend publishes, CloudEvents binary with the ce- prefix when unset, and Settings.Reads is the chain it reads with, binary then structured when unset. String headers no format takes reach a handler as Delivery.Foreign (messaging spec 0014).
Specified by https://gitlab.com/phpboyscout/go/messaging/-/wikis/specs/0009-the-rabbitmq-backend
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.NewSentinel("messaging_rabbitmq.closed", "messaging-rabbitmq: the session is closed")
ErrClosed is returned by Publish and Subscribe after Close.
var ErrManagement = errors.NewSentinel("messaging_rabbitmq.management",
"messaging-rabbitmq: the management API is not answering; this backend verifies every queue through it")
ErrManagement is returned by Open when the management API is unreachable or disabled: every claim about a queue comes from it (0009 D1).
var ErrNoExchange = errors.NewSentinel("messaging_rabbitmq.no_exchange",
"messaging-rabbitmq: the exchange this backend is bound to does not exist; a bus binds to an exchange and never creates one")
ErrNoExchange is returned by Open when the configured exchange does not exist: the bus binds, and never creates (0005 D9, 0009 D2).
var ErrNoQueue = errors.NewSentinel("messaging_rabbitmq.no_queue",
"messaging-rabbitmq: the queue this subscription consumes does not exist; a bus resolves a queue and never creates one")
ErrNoQueue is returned by Subscribe when the queue a subscription names does not exist.
var ErrUnroutable = errors.NewSentinel("messaging_rabbitmq.unroutable",
"messaging-rabbitmq: no queue is bound for this subject; the exchange returned the message")
ErrUnroutable is returned by Publish when no queue is bound for the subject: refused rather than dropped (0009 D11).
Functions ¶
Types ¶
type Management ¶
type Management struct {
// URL is the API's base, such as http://host:15672.
URL string
Username string
Password string
// VHost is the virtual host, "/" when empty.
VHost string
}
Management is the HTTP management API's endpoint and credentials.
type Settings ¶
type Settings struct {
// URL is the AMQP 0-9-1 endpoint, amqp:// or amqps://, credentials
// included.
URL string
// Management is the HTTP management API.
Management Management
// Exchange is the operator's topic exchange: the subject space. It must
// exist; Open fails naming it otherwise (0009 D2).
Exchange string
// Topology resolves the queue a subscription consumes. Nil means the
// durable name is the queue's name (0009 D3). An operator's tool may
// create on resolve; a test fixture is one.
Topology Topology
// DefaultAckWait is the lease when a subscription asks for none. Zero
// means thirty seconds (0009 D9): the broker's own timeout is not a lease.
DefaultAckWait time.Duration
// Logger receives what the backend cannot return. Nil discards.
Logger *slog.Logger
// Format writes every event this backend publishes. Unset, it is
// CloudEvents binary with the ce- prefix (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 with the ce- prefix, then
// structured.
Reads []envelope.Format
}
Settings is what the backend is built from (0009 D1). Both endpoints are required: management is a dependency, not a hedge, because every claim this backend makes about a queue comes from it.
type Topology ¶
type Topology interface {
// Queue is the name of the quorum queue for an at-least-once
// subscription. The spec is the subscription's, so an operator's tool
// can see what it asks for.
Queue(ctx context.Context, spec messaging.SourceSpec) (string, error)
}
Topology is the operator's answer to which queue a subscription consumes (0009 D3). The module verifies and never creates; a Topology that creates is the operator's tool.