Documentation
¶
Overview ¶
Package rabbitmqqueue provides bounded, RabbitMQ-native policy for AMQP 0-9-1 classic and quorum queues.
The package deliberately keeps queue semantics such as exchanges, routing, publisher outcomes, manual settlement, queue types, and recovery visible. It does not provide a backend-neutral queue abstraction and does not claim exactly-once processing.
Index ¶
- Constants
- Variables
- type Binding
- type ConnectionBlockedState
- type ConnectionConfig
- type Consumer
- func (consumer *Consumer) Close(ctx context.Context) error
- func (consumer *Consumer) DependencyHealth() DependencyHealth
- func (consumer *Consumer) Done() <-chan struct{}
- func (consumer *Consumer) Drain(ctx context.Context) error
- func (consumer *Consumer) Err() error
- func (consumer *Consumer) Liveness() Liveness
- func (consumer *Consumer) Observations() <-chan Observation
- func (consumer *Consumer) Pause() error
- func (consumer *Consumer) Readiness() Readiness
- func (consumer *Consumer) Resume() error
- func (consumer *Consumer) Shutdown(ctx context.Context) error
- type ConsumerConfig
- type CredentialProvider
- type CredentialProviderFunc
- type Credentials
- type DeadLetterStrategy
- type Death
- type DelayedRetryType
- type Delivery
- type DeliveryHandler
- type DeliveryMode
- type DependencyHealth
- type DevelopmentTopologyPermit
- type Endpoint
- type Exchange
- type ExchangeKind
- type Header
- type HeaderKind
- type Limits
- type Liveness
- type Message
- type Observation
- type ObservationKind
- type ObservationOutcome
- type ObservationResource
- type Producer
- func (producer *Producer) BlockedNotifications() <-chan ConnectionBlockedState
- func (producer *Producer) Close(ctx context.Context) error
- func (producer *Producer) DependencyHealth() DependencyHealth
- func (producer *Producer) IsBlocked() bool
- func (producer *Producer) Liveness() Liveness
- func (producer *Producer) Observations() <-chan Observation
- func (producer *Producer) Publish(ctx context.Context, publication Publication) (PublishResult, error)
- func (producer *Producer) PublishAsync(ctx context.Context, publication Publication) (<-chan PublishOutcome, error)
- func (producer *Producer) PublishBatch(ctx context.Context, publications []Publication) ([]PublishOutcome, error)
- func (producer *Producer) Readiness() Readiness
- func (producer *Producer) Shutdown(ctx context.Context) error
- type ProducerConfig
- type Publication
- type PublishOutcome
- type PublishResult
- type PublishState
- type Queue
- type QueueDeadLetter
- type QueueDelayedRetry
- type QueueDeliveryLimit
- type QueueOverflow
- type QueueReference
- type QueueType
- type Readiness
- type RecoveryPolicy
- type Return
- type Settlement
- type SettlementMethod
- type TLSConfig
- type Topology
- type TopologyMode
- type TopologyPolicy
- type TopologyResult
- type TransientQueue
Examples ¶
Constants ¶
const ( // MaxEndpoints bounds endpoint rotation and diagnostic state. MaxEndpoints = 16 // MaxReconnectAttempts bounds one continuous recovery episode. MaxReconnectAttempts = 32 // MaxRootCAs bounds custom trust-store parsing and retained certificate state. MaxRootCAs = 16 // MaxTLSMaterialBytes bounds aggregate roots, certificate, and private-key bytes. MaxTLSMaterialBytes = 1 << 20 )
const ( MaxConsumerPrefetch = 4096 MaxConsumerConcurrency = 256 MaxConsumerRequeues = 100 MaxDeathRecords = 128 MaxDeathRoutingKeys = 32 )
const ( MaxOutstandingConfirms = 4096 MaxPublishBatchSize = 1024 )
const ( // MaxTopologyExchanges bounds one topology operation's exchange set. MaxTopologyExchanges = 128 // MaxTopologyQueues bounds one topology operation's queue set. MaxTopologyQueues = 128 // MaxTopologyBindings bounds one development declaration's binding set. MaxTopologyBindings = 512 )
Variables ¶
var ( // ErrInvalidEndpoint means a connection endpoint is missing or unsafe. ErrInvalidEndpoint = errors.New("rabbitmqqueue: invalid endpoint") // ErrCredentialsRequired means no rotating credential provider was supplied. ErrCredentialsRequired = errors.New("rabbitmqqueue: credentials are required") // ErrInvalidTLS means verified TLS configuration is incomplete or unsafe. ErrInvalidTLS = errors.New("rabbitmqqueue: invalid TLS configuration") // ErrInvalidBounds means a configured resource or time bound is invalid. ErrInvalidBounds = errors.New("rabbitmqqueue: invalid resource bounds") // ErrInvalidVirtualHost means the AMQP virtual-host identity is invalid. ErrInvalidVirtualHost = errors.New("rabbitmqqueue: invalid virtual host") // ErrUnsupportedQueuePolicy means a queue option is not supported by its queue type. ErrUnsupportedQueuePolicy = errors.New("rabbitmqqueue: unsupported queue policy") // ErrUnsupportedExchangeKind means the exchange kind is not an AMQP built-in supported here. ErrUnsupportedExchangeKind = errors.New("rabbitmqqueue: unsupported exchange kind") // ErrInvalidTopology means a topology identity or property is invalid. ErrInvalidTopology = errors.New("rabbitmqqueue: invalid topology") // ErrTopologyMutationDenied means active declaration lacks a development-only permit. ErrTopologyMutationDenied = errors.New("rabbitmqqueue: topology mutation denied") // ErrPassiveBindingVerificationUnsupported means AMQP cannot inspect a binding without mutating it. ErrPassiveBindingVerificationUnsupported = errors.New("rabbitmqqueue: passive binding verification unsupported") ErrTopologyUnavailable = errors.New("rabbitmqqueue: topology unavailable") // ErrTopologyInequivalent means broker topology exists with incompatible declaration properties. ErrTopologyInequivalent = errors.New("rabbitmqqueue: topology is inequivalent") ErrTopologyUnauthorized = errors.New("rabbitmqqueue: topology access denied") // ErrMessageIDRequired means a publication has no stable application message identity. ErrMessageIDRequired = errors.New("rabbitmqqueue: message ID is required") // ErrPayloadTooLarge means a payload exceeds the configured byte limit. ErrPayloadTooLarge = errors.New("rabbitmqqueue: payload is too large") // ErrHeadersTooLarge means header count or bytes exceed configured limits. ErrHeadersTooLarge = errors.New("rabbitmqqueue: headers are too large") // ErrDuplicateHeader means a message repeats a header key. ErrDuplicateHeader = errors.New("rabbitmqqueue: duplicate header") // ErrInvalidHeader means a header key or value is outside the stable policy surface. ErrInvalidHeader = errors.New("rabbitmqqueue: invalid header") // ErrInvalidPriority means a message priority is outside the AMQP octet range. ErrInvalidPriority = errors.New("rabbitmqqueue: invalid priority") // ErrInvalidExpiration means a message expiration is negative or cannot be encoded safely. ErrInvalidExpiration = errors.New("rabbitmqqueue: invalid expiration") // ErrInvalidPublication means publication routing or properties are invalid. ErrInvalidPublication = errors.New("rabbitmqqueue: invalid publication") // ErrOutstandingConfirmLimit means the bounded in-flight publish window is full. ErrOutstandingConfirmLimit = errors.New("rabbitmqqueue: outstanding confirm limit reached") // ErrInvalidBatch means a publish batch is empty, oversized, or contains invalid work. ErrInvalidBatch = errors.New("rabbitmqqueue: invalid publish batch") // ErrInvalidPublishCorrelation means a publish sequence or internal token is invalid or reused. ErrInvalidPublishCorrelation = errors.New("rabbitmqqueue: invalid publish correlation") // ErrContextRequired means an operation received a nil context. ErrContextRequired = errors.New("rabbitmqqueue: context is required") // ErrProducerClosed means the producer no longer accepts publications. ErrProducerClosed = errors.New("rabbitmqqueue: producer is closed") ErrProducerUnavailable = errors.New("rabbitmqqueue: producer is unavailable") // ErrPublishReturned means mandatory routing returned the publication. ErrPublishReturned = errors.New("rabbitmqqueue: publication was returned") // ErrPublishRejected means the broker negatively confirmed the publication. ErrPublishRejected = errors.New("rabbitmqqueue: publication was rejected") // ErrPublishAmbiguous means transmission began but no definitive broker result was observed. ErrPublishAmbiguous = errors.New("rabbitmqqueue: publication outcome is ambiguous") // ErrReservedHeader means application metadata collides with package- or broker-owned delivery state. ErrReservedHeader = errors.New("rabbitmqqueue: reserved header") // ErrInvalidConsumer means consumer identity, bounds, or failure policy is invalid. ErrInvalidConsumer = errors.New("rabbitmqqueue: invalid consumer") // ErrInvalidDelivery means broker delivery data exceeds the safe public policy surface. ErrInvalidDelivery = errors.New("rabbitmqqueue: invalid delivery") // ErrInvalidSettlement means a handler requested an undefined settlement operation. ErrInvalidSettlement = errors.New("rabbitmqqueue: invalid settlement") ErrSettlementResultUnavailable = errors.New("rabbitmqqueue: settlement result is unavailable") // ErrConsumerClosed means a stopped consumer cannot change admission state. ErrConsumerClosed = errors.New("rabbitmqqueue: consumer is closed") ErrConsumerUnavailable = errors.New("rabbitmqqueue: consumer is unavailable") )
Functions ¶
This section is empty.
Types ¶
type Binding ¶
Binding identifies one queue binding without exposing a raw AMQP field table. Arguments are supported only for headers exchanges; other built-in exchange kinds use the explicit routing key.
type ConnectionBlockedState ¶
type ConnectionBlockedState struct {
Active bool
}
ConnectionBlockedState reports whether RabbitMQ has temporarily blocked publishing on the owned connection. Broker-provided reason text is omitted.
type ConnectionConfig ¶
type ConnectionConfig struct {
Endpoints []Endpoint
VirtualHost string
Credentials CredentialProvider
TLS TLSConfig
DialTimeout time.Duration
Heartbeat time.Duration
Recovery RecoveryPolicy
}
ConnectionConfig owns connection, authentication, TLS, heartbeat, and recovery policy. It contains no formatted URI so credentials cannot leak through ordinary diagnostics.
func (ConnectionConfig) Validate ¶
func (config ConnectionConfig) Validate() error
Validate rejects unbounded, secret-bearing, or unverifiable connection policy.
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
Consumer owns one active manual-acknowledgement generation and a bounded worker pool. Runtime recovery replaces the complete connection/channel/ consumer generation before admitting more broker deliveries.
func OpenConsumer ¶
func OpenConsumer( ctx context.Context, connection ConnectionConfig, config ConsumerConfig, handler DeliveryHandler, ) (*Consumer, error)
OpenConsumer establishes an independent consumer-only AMQP connection, applies bounded per-consumer QoS, and starts manual-settlement workers.
func (*Consumer) DependencyHealth ¶
func (consumer *Consumer) DependencyHealth() DependencyHealth
DependencyHealth reports consumer connection state independently of liveness.
func (*Consumer) Done ¶
func (consumer *Consumer) Done() <-chan struct{}
Done closes after broker intake stops and all admitted handlers return.
func (*Consumer) Drain ¶
Drain cancels broker intake and waits for every delivery already received from the broker. It leaves the healthy owned connection open after complete settlement; delegated work or a drain deadline closes the connection.
func (*Consumer) Observations ¶
func (consumer *Consumer) Observations() <-chan Observation
Observations returns the bounded best-effort consumer event stream. It closes after broker intake and all admitted handlers stop.
func (*Consumer) Pause ¶
Pause stops new handler admission without cancelling the active broker consumer. Already admitted handlers continue through settlement. Up to the configured prefetch may be held unsettled until Resume. Pause is idempotent.
func (*Consumer) Readiness ¶
Readiness reports whether the consumer currently admits broker deliveries.
func (*Consumer) Shutdown ¶ added in v1.1.0
Shutdown stops handler admission, drains admitted handlers, then closes owned resources. Broker deliveries buffered before admission are left unsettled for redelivery and make an overlapping Drain report ErrConsumerUnavailable. It is safe to call repeatedly or concurrently. Each caller waits only for its own context; cleanup continues after a caller returns early. If cancellation or the internal drain deadline fails, resources are still closed for redelivery.
type ConsumerConfig ¶
type ConsumerConfig struct {
Limits Limits
Queue QueueReference
Name string
Priority *int32
Exclusive bool
Prefetch int
Concurrency int
HandlerTimeout time.Duration
MaxRequeues uint32
Failure Settlement
}
ConsumerConfig bounds one independent manual-settlement consumer. Priority distinguishes an omitted RabbitMQ default from an explicit signed value, including zero. Exclusive requests classic-queue exclusivity and cannot be combined with single-active-consumer topology. HandlerTimeout also bounds settlement and supplies the shutdown fallback; handlers must observe their context for graceful draining. MaxRequeues uses RabbitMQ 4.3's quorum acquired count when available and otherwise permits at most one redelivery.
func (ConsumerConfig) Validate ¶
func (config ConsumerConfig) Validate() error
Validate rejects unbounded consumption and unsafe automatic failure outcomes.
type CredentialProvider ¶
type CredentialProvider interface {
Credentials(context.Context) (Credentials, error)
}
CredentialProvider resolves credentials for an individual connection attempt. Implementations may be called concurrently by independent producers and consumers. Package-owned connection attempts supply a non-nil, bounded context. Calls are synchronous, are never made while a package lock is held, and panics are not recovered. Implementations must return when the supplied context is cancelled.
type CredentialProviderFunc ¶
type CredentialProviderFunc func(context.Context) (Credentials, error)
CredentialProviderFunc adapts a function to CredentialProvider. The function must follow CredentialProvider's concurrency, cancellation, and panic rules.
Example ¶
package main
import (
"context"
"fmt"
rabbitmqqueue "github.com/faustbrian/go-rabbitmq-queues"
)
func main() {
provider := rabbitmqqueue.CredentialProviderFunc(
func(context.Context) (rabbitmqqueue.Credentials, error) {
return rabbitmqqueue.Credentials{
Username: "orders",
Password: []byte("resolved-attempt-secret"),
}, nil
},
)
credentials, err := provider.Credentials(context.Background())
fmt.Println(credentials.Username, err)
clear(credentials.Password)
}
Output: orders <nil>
func (CredentialProviderFunc) Credentials ¶
func (provider CredentialProviderFunc) Credentials(ctx context.Context) (Credentials, error)
Credentials resolves a fresh caller-owned credential snapshot. OpenProducer, OpenConsumer, and ApplyTopology zero their returned password snapshot after each connection attempt. Direct callers and providers remain responsible for snapshots and aliases they retain.
type Credentials ¶
Credentials are an owned authentication snapshot. Providers should return a fresh password slice on every call so reconnection can observe rotation.
type DeadLetterStrategy ¶
type DeadLetterStrategy string
DeadLetterStrategy selects quorum queue dead-letter transfer guarantees. The zero value leaves the broker's at-most-once default implicit.
const ( DeadLetterAtMostOnce DeadLetterStrategy = "at-most-once" DeadLetterAtLeastOnce DeadLetterStrategy = "at-least-once" )
type Death ¶
type Death struct {
Count uint64
Reason string
Queue string
Exchange string
RoutingKeys []string
Time time.Time
OriginalExpiration *time.Duration
}
Death preserves one bounded RabbitMQ x-death record without exposing a raw field table.
type DelayedRetryType ¶
type DelayedRetryType string
DelayedRetryType selects which RabbitMQ 4.3 quorum redeliveries receive broker-managed linear backoff.
const ( DelayedRetryDisabled DelayedRetryType = "disabled" DelayedRetryAll DelayedRetryType = "all" DelayedRetryFailed DelayedRetryType = "failed" DelayedRetryReturned DelayedRetryType = "returned" )
type Delivery ¶
type Delivery struct {
Body []byte
Headers []Header
MessageID string
CorrelationID string
ContentType string
ContentEncoding string
ReplyTo string
Type string
UserID string
AppID string
Timestamp time.Time
// Expiration distinguishes an omitted TTL from RabbitMQ's explicit
// zero-duration immediate-expiration value.
Expiration *time.Duration
Priority uint8
DeliveryMode DeliveryMode
Consumer string
Exchange string
RoutingKey string
Redelivered bool
AcquiredCount *uint64
DeliveryCount *uint64
Deaths []Death
// contains filtered or unexported fields
}
Delivery is an owned, bounded AMQP delivery snapshot. Delivery tags and the underlying client delivery never cross the public API boundary.
func (Delivery) AwaitSettlement ¶
AwaitSettlement waits for the broker result of the settlement selected by the delivery handler. The handler must first return its Settlement; waiting synchronously inside that handler cannot complete. A separate goroutine may wait on a copied Delivery while the handler returns. Copies share the same bounded result. The method returns ErrSettlementResultUnavailable for deliveries not created by a Consumer or whose handler delegated settlement.
type DeliveryHandler ¶
type DeliveryHandler func(context.Context, Delivery) (Settlement, error)
DeliveryHandler processes one owned delivery and returns its explicit manual settlement.
type DeliveryMode ¶
type DeliveryMode uint8
DeliveryMode selects broker persistence intent.
const ( DeliveryTransient DeliveryMode = iota + 1 DeliveryPersistent )
type DependencyHealth ¶
type DependencyHealth string
DependencyHealth reports the owned RabbitMQ dependency state separately from process liveness.
const ( DependencyAvailable DependencyHealth = "available" DependencyBlocked DependencyHealth = "blocked" DependencyRecovering DependencyHealth = "recovering" DependencyUnknown DependencyHealth = "unknown" )
type DevelopmentTopologyPermit ¶
type DevelopmentTopologyPermit struct {
// contains filtered or unexported fields
}
DevelopmentTopologyPermit is an explicit capability for test and local topology declaration. Its zero value never permits mutation.
func PermitDevelopmentTopology ¶
func PermitDevelopmentTopology() DevelopmentTopologyPermit
PermitDevelopmentTopology explicitly opts a development or test process into topology mutation. Production applications must not call this function.
type Exchange ¶
type Exchange struct {
Name string
Kind ExchangeKind
Durable bool
AutoDelete bool
Internal bool
}
Exchange is a stable exchange identity and equivalence policy.
type ExchangeKind ¶
type ExchangeKind string
ExchangeKind selects a RabbitMQ built-in AMQP exchange algorithm.
const ( ExchangeDirect ExchangeKind = "direct" ExchangeTopic ExchangeKind = "topic" ExchangeFanout ExchangeKind = "fanout" ExchangeHeaders ExchangeKind = "headers" )
type Header ¶
Header is one ordered AMQP application header. Nested tables and arrays are intentionally excluded to keep allocation and interoperability bounded.
func BoolHeader ¶
BoolHeader creates a boolean application header.
func BytesHeader ¶
BytesHeader creates a byte-string application header with an owned value copy.
func Int64Header ¶
Int64Header creates a signed 64-bit integer application header.
func StringHeader ¶
StringHeader creates a string application header.
type HeaderKind ¶
type HeaderKind uint8
HeaderKind identifies a bounded, language-neutral AMQP field-table value.
const ( HeaderString HeaderKind = iota + 1 HeaderBool HeaderInt64 HeaderBytes )
type Limits ¶
type Limits struct {
MaxPayloadBytes int
MaxHeaderEntries int
MaxHeaderBytes int
MaxNameBytes int
MaxRoutingKeyBytes int
}
Limits bounds untrusted message and topology-controlled allocation. Values may be lowered from DefaultLimits but cannot raise the package safety caps.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits returns conservative RabbitMQ 4.x policy bounds.
type Liveness ¶
type Liveness string
Liveness is process-supervision state for one package resource. Temporary dependency outages remain live while bounded recovery is active.
type Message ¶
type Message struct {
Body []byte
MessageID string
CorrelationID string
ReplyTo string
ContentType string
ContentEncoding string
Type string
AppID string
// Timestamp is either zero or a non-negative whole-second AMQP timestamp.
Timestamp time.Time
// Expiration distinguishes an omitted TTL from an explicit zero-duration
// TTL, which RabbitMQ interprets as immediate expiration when the message
// cannot be delivered directly.
Expiration *time.Duration
Priority *uint16
Headers []Header
}
Message contains AMQP message properties and opaque payload bytes.
type Observation ¶
type Observation struct {
Resource ObservationResource
Kind ObservationKind
Outcome ObservationOutcome
Duration time.Duration
Dropped uint64
}
Observation is a payload-free, identifier-free operational event. Duration is populated only for confirmation latency. Dropped reports observations discarded since the previous delivered event because the bounded stream was full. Stream closure emits ObservationStreamClosed and reserves a buffered slot when necessary so undisclosed tail loss remains visible.
type ObservationKind ¶
type ObservationKind string
ObservationKind is a fixed low-cardinality operational event category.
const ( ObservationConnectionState ObservationKind = "connection_state" ObservationConnectionBlocked ObservationKind = "connection_blocked" ObservationReconnect ObservationKind = "reconnect" ObservationPublish ObservationKind = "publish" ObservationReturn ObservationKind = "return" ObservationConfirm ObservationKind = "confirm" ObservationConfirmationLatency ObservationKind = "confirmation_latency" ObservationAmbiguous ObservationKind = "ambiguous" ObservationDelivery ObservationKind = "delivery" ObservationRedelivery ObservationKind = "redelivery" ObservationConsumerCancellation ObservationKind = "consumer_cancellation" ObservationAcknowledgement ObservationKind = "acknowledgement" ObservationSettlement ObservationKind = "settlement" ObservationHandlerFailure ObservationKind = "handler_failure" ObservationDeadLetter ObservationKind = "dead_letter" ObservationBacklogPressure ObservationKind = "backlog_pressure" ObservationShutdown ObservationKind = "shutdown" ObservationStreamClosed ObservationKind = "stream_closed" )
type ObservationOutcome ¶
type ObservationOutcome string
ObservationOutcome is a fixed low-cardinality event result or transition.
const ( ObservationConnected ObservationOutcome = "connected" ObservationRecovering ObservationOutcome = "recovering" ObservationRecovered ObservationOutcome = "recovered" ObservationBlocked ObservationOutcome = "blocked" ObservationUnblocked ObservationOutcome = "unblocked" ObservationAttempted ObservationOutcome = "attempted" ObservationConfirmed ObservationOutcome = "confirmed" ObservationRejected ObservationOutcome = "rejected" ObservationReturned ObservationOutcome = "returned" ObservationNotSent ObservationOutcome = "not_sent" ObservationAmbiguousOutcome ObservationOutcome = "ambiguous" ObservationDelivered ObservationOutcome = "delivered" ObservationRedelivered ObservationOutcome = "redelivered" ObservationCancelled ObservationOutcome = "cancelled" ObservationAcknowledged ObservationOutcome = "acknowledged" ObservationNegativeAcknowledged ObservationOutcome = "negative_acknowledged" ObservationHandlerFailed ObservationOutcome = "failed" ObservationDeadLettered ObservationOutcome = "dead_lettered" ObservationBacklogFull ObservationOutcome = "full" ObservationShutdownStarted ObservationOutcome = "started" ObservationShutdownCompleted ObservationOutcome = "completed" ObservationClosed ObservationOutcome = "closed" )
type ObservationResource ¶
type ObservationResource string
ObservationResource identifies the bounded package resource that emitted an observation without exposing a connection, route, message, or consumer ID.
const ( ObservationProducer ObservationResource = "producer" ObservationConsumer ObservationResource = "consumer" )
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
Producer owns one active confirm-enabled AMQP generation and never creates consumers. Publish is safe for concurrent use. Shutdown prevents new work, drains bounded active calls, cancels recovery, and then releases the channel and connection resource.
func OpenProducer ¶
func OpenProducer( ctx context.Context, connection ConnectionConfig, config ProducerConfig, ) (*Producer, error)
OpenProducer establishes an independent producer-only AMQP connection and confirm-enabled channel. Startup and bounded runtime recovery attempts rotate endpoints and credentials. Exhausted runtime recovery is terminal.
func (*Producer) BlockedNotifications ¶
func (producer *Producer) BlockedNotifications() <-chan ConnectionBlockedState
BlockedNotifications emits coalesced sanitized state transitions. The channel closes when the producer lifecycle ends.
func (*Producer) DependencyHealth ¶
func (producer *Producer) DependencyHealth() DependencyHealth
DependencyHealth reports producer connection state independently of liveness.
func (*Producer) IsBlocked ¶
IsBlocked reports the latest sanitized RabbitMQ connection-blocked state.
func (*Producer) Observations ¶
func (producer *Producer) Observations() <-chan Observation
Observations returns the bounded best-effort producer event stream. The stream closes after Shutdown completes; terminal recovery alone does not release caller-owned observation consumption.
func (*Producer) Publish ¶
func (producer *Producer) Publish(ctx context.Context, publication Publication) (PublishResult, error)
Publish sends one publication and waits for its exact mandatory-return and confirmation outcome. A timeout after transmission is always ambiguous.
func (*Producer) PublishAsync ¶
func (producer *Producer) PublishAsync(ctx context.Context, publication Publication) (<-chan PublishOutcome, error)
PublishAsync admits one bounded publication and returns a channel that emits exactly one terminal outcome. Its caller context and PublishTimeout bound the total interval from admission through transmission and confirmation; expiry before transmission reports PublishNotSent. Admission failures do not create goroutines.
func (*Producer) PublishBatch ¶
func (producer *Producer) PublishBatch(ctx context.Context, publications []Publication) ([]PublishOutcome, error)
PublishBatch validates the complete bounded batch before publishing each item. Outcomes preserve input order; the batch is not an atomic broker unit.
func (*Producer) Shutdown ¶ added in v1.1.0
Shutdown prevents new publications, waits for active bounded calls, and closes owned AMQP resources. It is safe to call repeatedly or concurrently. Each caller waits only for its own context; cleanup continues after a caller returns early. Cancellation or deadline expiry from any caller accelerates the shared cleanup by forcing the owned connection closed, making any still-active publication ambiguous.
type ProducerConfig ¶
ProducerConfig bounds synchronous producer work and confirmation state.
func (ProducerConfig) Validate ¶
func (config ProducerConfig) Validate() error
Validate rejects unbounded producer policy.
type Publication ¶
type Publication struct {
// Exchange is a named exchange identity, or the empty default-exchange
// identity when ExchangeKind is explicitly ExchangeDirect.
Exchange string
// ExchangeKind records the expected routing semantic for local validation.
// Omit it only for non-empty direct/topic-compatible routing keys. An
// explicit direct or topic kind may use RabbitMQ's native empty key; fanout
// and headers publications must name their kind and use an empty key.
ExchangeKind ExchangeKind
RoutingKey string
Mandatory bool
DeliveryMode DeliveryMode
Message Message
}
Publication binds one message to explicit AMQP routing policy.
func (Publication) Validate ¶
func (publication Publication) Validate(limits Limits) error
Validate bounds and validates publication routing, properties, and headers.
type PublishOutcome ¶
type PublishOutcome struct {
Result PublishResult
Err error
}
PublishOutcome pairs one terminal result with its sanitized operation error. Batch outcomes preserve input order; asynchronous outcomes are delivered once.
type PublishResult ¶
type PublishResult struct {
State PublishState
Return *Return
}
PublishResult is the terminal observed state for exactly one publish attempt.
func (PublishResult) Valid ¶
func (result PublishResult) Valid() bool
Valid reports whether the state and mandatory-return detail form a canonical outcome.
type PublishState ¶
type PublishState string
PublishState distinguishes broker outcomes without collapsing post-send cancellation or connection loss into a definitive result.
const ( PublishNotSent PublishState = "not_sent" PublishRejected PublishState = "rejected" PublishReturned PublishState = "returned" PublishConfirmed PublishState = "confirmed" PublishAmbiguous PublishState = "ambiguous" )
func (PublishState) Valid ¶
func (state PublishState) Valid() bool
Valid reports whether state is a defined publication outcome.
type Queue ¶
type Queue struct {
Name string
Type QueueType
Durable bool
AutoDelete bool
Exclusive bool
SingleActiveConsumer bool
DeliveryLimit *QueueDeliveryLimit
MaxPriority uint8
MessageTTL *time.Duration
Expires *time.Duration
ConsumerTimeout *time.Duration
DisconnectedConsumerTimeout *time.Duration
DelayedRetry *QueueDelayedRetry
MaxLength *uint64
MaxLengthBytes *uint64
Overflow QueueOverflow
DeadLetter *QueueDeadLetter
}
Queue describes declaration-equivalent queue policy. A zero Name requests a server-generated name and is valid only for an exclusive classic queue. MessageTTL and the length pointers distinguish an explicit zero argument from omission. Expires, when present, must be a positive millisecond value. A nil DeliveryLimit preserves the broker policy or default; a pointer emits an explicit bounded value, including zero. ConsumerTimeout is RabbitMQ 4.3's quorum-only delivery-acknowledgement timeout and accepts non-negative values with millisecond precision. DisconnectedConsumerTimeout is RabbitMQ 4.3's quorum-only wait before held deliveries are returned after a consumer node becomes unreachable. DelayedRetry is RabbitMQ 4.3's quorum-only linear-backoff policy.
type QueueDeadLetter ¶
type QueueDeadLetter struct {
Exchange string
RoutingKey *string
Strategy DeadLetterStrategy
}
QueueDeadLetter describes declaration-time dead-letter arguments. An empty Exchange explicitly selects the AMQP default exchange. A nil RoutingKey omits the argument and preserves original routing keys; a pointer to an empty string emits an explicit empty routing key. RabbitMQ policies are preferred for production configuration because they remain mutable.
type QueueDelayedRetry ¶
type QueueDelayedRetry struct {
Type DelayedRetryType
Minimum time.Duration
Maximum *time.Duration
}
QueueDelayedRetry describes RabbitMQ 4.3 quorum delayed-retry arguments. Enabled retry requires a positive millisecond Minimum. A nil Maximum uses a fixed delay equal to Minimum; otherwise Maximum must not precede Minimum.
type QueueDeliveryLimit ¶
type QueueDeliveryLimit uint32
QueueDeliveryLimit bounds RabbitMQ quorum failed redeliveries. The unsigned policy intentionally cannot represent RabbitMQ's unsafe unlimited value -1.
type QueueOverflow ¶
type QueueOverflow string
QueueOverflow selects RabbitMQ's queue-length overflow behavior.
const ( QueueOverflowDropHead QueueOverflow = "drop-head" QueueOverflowRejectPublish QueueOverflow = "reject-publish" QueueOverflowRejectPublishDeadLetter QueueOverflow = "reject-publish-dlx" )
type QueueReference ¶
type QueueReference struct {
Name string
Type QueueType
SingleActiveConsumer bool
Transient *TransientQueue
}
QueueReference identifies either an existing operator-owned queue or an explicitly client-owned transient queue. SingleActiveConsumer records declaration intent for local policy validation; callers use passive topology verification when they need broker evidence for a named queue.
func (QueueReference) Validate ¶
func (reference QueueReference) Validate() error
Validate rejects missing queue identities and unsupported queue types.
type QueueType ¶
type QueueType string
QueueType distinguishes queue implementations whose policies are not interchangeable.
type Readiness ¶
type Readiness string
Readiness reports whether one resource can currently accept useful work.
type RecoveryPolicy ¶
RecoveryPolicy bounds reconnection attempts and exponential backoff.
type Return ¶
Return describes a mandatory unroutable outcome without carrying payloads or headers. Exchange and RoutingKey come from the exact registered publication, not untrusted broker return metadata.
type Settlement ¶
type Settlement struct {
Method SettlementMethod
Requeue bool
}
Settlement is a handler's explicit request for one delivery. Delegate leaves the delivery unsettled until the consumer drains, closes, or loses its connection.
func Acknowledge ¶
func Acknowledge() Settlement
Acknowledge requests a single-delivery ACK after handler success.
func Delegate ¶
func Delegate() Settlement
Delegate explicitly leaves settlement to the consumer connection lifecycle.
func NegativeAcknowledge ¶
func NegativeAcknowledge(requeue bool) Settlement
NegativeAcknowledge requests a single-delivery NACK.
func (Settlement) Validate ¶
func (settlement Settlement) Validate() error
Validate rejects unknown methods and impossible requeue flags.
type SettlementMethod ¶
type SettlementMethod string
SettlementMethod identifies one AMQP manual-settlement operation.
const ( SettlementAcknowledge SettlementMethod = "ack" SettlementNegativeAcknowledge SettlementMethod = "nack" SettlementReject SettlementMethod = "reject" SettlementDelegate SettlementMethod = "delegate" )
type TLSConfig ¶
type TLSConfig struct {
ServerName string
RootCAs [][]byte
ClientCertificate []byte
ClientPrivateKey []byte
}
TLSConfig owns verified TLS identity and optional custom trust material. Certificate and key bytes are secrets and must never be observed or logged.
type Topology ¶
Topology is one bounded exchange, queue, and binding graph. Passive AMQP verification can compare exchange and queue declarations, but AMQP 0-9-1 has no passive binding method. Bindings therefore require development declaration or separate infrastructure/operator verification.
func (Topology) Validate ¶
func (topology Topology) Validate(policy TopologyPolicy) error
Validate checks graph bounds, identities, references, exchange-specific binding rules, lifecycle-safe queues, and the passive-binding protocol limitation. Every exclusive queue belongs to its declaring connection; ApplyTopology cannot retain one because it closes that connection on return.
type TopologyMode ¶
type TopologyMode string
TopologyMode selects passive equivalence verification or active declaration.
const ( TopologyPassive TopologyMode = "passive" TopologyDeclare TopologyMode = "declare" )
type TopologyPolicy ¶
type TopologyPolicy struct {
Mode TopologyMode
Development DevelopmentTopologyPermit
}
TopologyPolicy keeps production verification distinct from development declaration.
func (TopologyPolicy) Validate ¶
func (policy TopologyPolicy) Validate() error
Validate prevents declaration without an explicit development-only capability.
type TopologyResult ¶
type TopologyResult struct {
QueueNames []string
}
TopologyResult returns verified or declared queue names in Topology.Queues order.
func ApplyTopology ¶
func ApplyTopology( ctx context.Context, connection ConnectionConfig, policy TopologyPolicy, topology Topology, ) (TopologyResult, error)
ApplyTopology passively verifies operator-owned exchange and queue equivalence, or performs explicitly permitted development-only declarations. AMQP cannot passively inspect bindings; Topology.Validate rejects passive binding requests rather than mutating production topology. Connection-scoped server-named queues are declared only by a client-owned transient consumer.
type TransientQueue ¶
TransientQueue describes an explicitly client-owned, connection-scoped, server-named classic queue bound to an existing exchange. The consumer declares and consumes it on the same connection so RabbitMQ can retain the exclusive queue for exactly that generation.