rabbitmq

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 8 Imported by: 0

README

go-queue RabbitMQ compatibility facade

Deprecated: use github.com/faustbrian/go-queue/adapters/rabbitmq. This released v1 path delegates to that semantic owner without copying mutable runtime state.

This module preserves the backend-neutral go-queue worker contract while delegating RabbitMQ connections, publishing, consumption, recovery, and broker settlement to go-rabbitmq-queues. New RabbitMQ-native applications should use that package directly.

Status and requirements

This is a deprecated stable-v1 compatibility module at rabbitmq/v1.0.3. It requires Go 1.27.0 or later.

Install

go get github.com/faustbrian/go-queue/rabbitmq

Quick start

config := rabbitmq.NativeConfig{
    Connection: rabbitmqqueue.ConnectionConfig{
        Endpoints: []rabbitmqqueue.Endpoint{{Host: "rabbitmq.internal", Port: 5671}},
        VirtualHost: "/orders",
        Credentials: credentialProvider,
        TLS: rabbitmqqueue.TLSConfig{ServerName: "rabbitmq.internal"},
        DialTimeout: 5 * time.Second,
        Heartbeat: 30 * time.Second,
        Recovery: rabbitmqqueue.RecoveryPolicy{
            MaxAttempts: 8,
            InitialDelay: 100 * time.Millisecond,
            MaxDelay: 5 * time.Second,
        },
    },
    Producer: rabbitmqqueue.ProducerConfig{
        Limits: rabbitmqqueue.DefaultLimits(),
        MaxOutstanding: 256,
        PublishTimeout: 5 * time.Second,
    },
    Consumer: rabbitmqqueue.ConsumerConfig{
        Limits: rabbitmqqueue.DefaultLimits(),
        Queue: rabbitmqqueue.QueueReference{Name: "orders", Type: rabbitmqqueue.QueueQuorum},
        Name: "orders-worker",
        Prefetch: 32,
        Concurrency: 8,
        HandlerTimeout: time.Minute,
        MaxRequeues: 1,
        Failure: rabbitmqqueue.Reject(false),
    },
    MessageID: func(task core.TaskMessage) (string, error) {
        return stableApplicationID(task)
    },
}

worker, err := rabbitmq.NewWorkerE(
    rabbitmq.WithNativeConfig(config),
    rabbitmq.WithQueue("orders"),
    rabbitmq.WithTag("orders-worker"),
    rabbitmq.WithExchangeName("orders.events"),
    rabbitmq.WithExchangeType(rabbitmq.ExchangeTopic),
    rabbitmq.WithRoutingKey("orders.created"),
)

The facade-owned examples provide complete imports and setup. This module's documentation gate compiles them and executes their observable validation example.

The producer opens during construction. The consumer opens lazily on the first Request, so publishing never creates a consumer.

API reference

  • NativeConfig binds the adapter to explicit native connection, producer, consumer, queue-type, and message-identity policy.
  • NewWorkerE returns setup failures; NewWorker retains the legacy panic-on- construction-failure behavior.
  • Worker.Queue, Worker.Request, Worker.Run, and Worker.Shutdown preserve the go-queue worker surface.
  • Existing routing and lifecycle options remain source-compatible where the adapter can preserve their semantics. WithNativeConfig is mandatory.

The complete exported API is available on pkg.go.dev.

For ecosystem-wide selection and ownership guidance, see the versioned Golib ecosystem index and Persistence and durability family guidance.

Topology ownership

Production exchanges, queues, bindings, dead-letter policy, and permissions remain infrastructure-owned, preferably by the RabbitMQ Kubernetes Operators. Configure NativeConfig with the same identities and queue type. The adapter does not declare or repair production topology.

Settlement and failure policy

  • Successful handlers ACK only after the native broker settlement completes.
  • A bare Nack and canceled or infrastructure failures requeue the source.
  • Retryable failures publish a mandatory persistent replacement with the same message ID and an incremented bounded attempt, then ACK the source only after confirmation.
  • Permanent, malformed, and exhausted failures publish to the configured terminal route with stable classification and source metadata before ACK.
  • Returned, rejected, not-sent, ambiguous, or failed replacement publications leave the source recoverable.

Replacement publication and source acknowledgement remain separate effects. A crash after the replacement is confirmed but before the source ACK can produce a duplicate. Applications must remain idempotent. The adapter never claims exactly-once processing.

Migration and rollback

  1. Create operator-owned source and terminal topology matching NativeConfig.
  2. Supply a stable outbound MessageID. For legacy deliveries without an AMQP message ID, optionally supply DeliveryMessageID; an error or empty result requeues the source.
  3. Deploy one bounded canary worker and verify publish confirmations, redeliveries, retry attempts, terminal records, backlog, and shutdown.
  4. Expand only after the old and adapter workers demonstrate compatible job outcomes. Do not run both implementations against incompatible topology or retry policy.
  5. Roll back by draining adapter consumers before restoring the prior worker. Retain the same topology and message-ID derivation so confirmed replacements and redeliveries remain deduplicatable.

Limitations

  • WithNativeConfig is required.
  • Manual acknowledgement is required; WithAutoAck(true) is rejected.
  • Direct and topic exchanges are supported. Fanout and headers are rejected because their legacy job migration semantics have not been established.
  • Native event distribution, RPC, independent fan-out, topology APIs, and advanced RabbitMQ policy are intentionally not projected through go-queue.
  • TLS verification is mandatory through go-rabbitmq-queues.

Security

Credential providers must return fresh owned credentials. Do not include credentials, certificates, payloads, or arbitrary headers in logs or errors. Message identity and failure codes must be stable, bounded, and non-sensitive.

CI broker evidence runs with Go 1.27.0 on Ubuntu 24.04 amd64 and RabbitMQ 4.3.5 over verified TLS.

FAQ

Should new services use this module?

Only when they must participate in a go-queue job workflow. Use go-rabbitmq-queues for RabbitMQ-native messaging.

Does a successful publish mean the handler ran?

No. It means RabbitMQ confirmed the mandatory publication and did not return it as unroutable. Consumer execution and settlement happen later.

Does broker recovery make processing exactly once?

No. Delivery and settlement remain at least once, and replacement publication has an explicit duplicate window.

Release notes

See CHANGELOG.md for module-specific behavior and migration changes. This module uses directory-prefixed tags such as rabbitmq/v1.0.0.

Support and repository policies

Documentation

Overview

Package rabbitmq preserves the released RabbitMQ adapter import path.

Deprecated: use github.com/faustbrian/go-queue/adapters/rabbitmq.

Index

Examples

Constants

View Source
const (
	// ExchangeDirect retains the legacy direct exchange name.
	//
	// Deprecated: use successor.ExchangeDirect.
	ExchangeDirect = successor.ExchangeDirect
	// ExchangeFanout retains the legacy constant; the native adapter rejects it.
	//
	// Deprecated: use successor.ExchangeFanout.
	ExchangeFanout = successor.ExchangeFanout
	// ExchangeTopic retains the legacy topic exchange name.
	//
	// Deprecated: use successor.ExchangeTopic.
	ExchangeTopic = successor.ExchangeTopic
	// ExchangeHeaders retains the legacy constant; the native adapter rejects it.
	//
	// Deprecated: use successor.ExchangeHeaders.
	ExchangeHeaders = successor.ExchangeHeaders
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeadLetterConfig deprecated

type DeadLetterConfig struct {
	// Exchange is the terminal exchange.
	Exchange string
	// Queue is the terminal queue.
	Queue string
	// RoutingKey is the terminal routing key.
	RoutingKey string
	// MaxDeliveryAttempts bounds delivery attempts before terminal routing.
	MaxDeliveryAttempts uint32
}

DeadLetterConfig preserves the released terminal-route configuration.

Deprecated: use successor.DeadLetterConfig.

type NativeConfig deprecated

type NativeConfig struct {
	// Connection configures the caller-approved native connection.
	Connection rabbitmqqueue.ConnectionConfig
	// Producer configures confirmed mandatory publication.
	Producer rabbitmqqueue.ProducerConfig
	// Consumer configures bounded manual-settlement consumption.
	Consumer rabbitmqqueue.ConsumerConfig
	// MessageID derives stable identity for an outgoing task.
	MessageID func(core.TaskMessage) (string, error)
	// DeliveryMessageID derives identity for a decoded broker delivery.
	DeliveryMessageID func(rabbitmqqueue.Delivery, *job.Message) (string, error)
}

NativeConfig preserves the released explicit RabbitMQ policy boundary.

Deprecated: use successor.NativeConfig.

Example
package main

import (
	"context"
	"time"

	"github.com/faustbrian/go-queue/core"

	rabbitmq "github.com/faustbrian/go-queue/rabbitmq"

	rabbitmqqueue "github.com/faustbrian/go-rabbitmq-queues"
)

func main() {
	credentials := rabbitmqqueue.CredentialProviderFunc(
		func(context.Context) (rabbitmqqueue.Credentials, error) {
			return rabbitmqqueue.Credentials{Username: "worker", Password: []byte("example-only")}, nil
		},
	)
	_, _ = rabbitmq.NewWorkerE(
		rabbitmq.WithNativeConfig(rabbitmq.NativeConfig{
			Connection: rabbitmqqueue.ConnectionConfig{
				Endpoints:   []rabbitmqqueue.Endpoint{{Host: "rabbitmq.internal", Port: 5671}},
				VirtualHost: "/", Credentials: credentials,
				TLS:         rabbitmqqueue.TLSConfig{ServerName: "rabbitmq.internal"},
				DialTimeout: 5 * time.Second, Heartbeat: 30 * time.Second,
				Recovery: rabbitmqqueue.RecoveryPolicy{
					MaxAttempts: 8, InitialDelay: 100 * time.Millisecond, MaxDelay: 5 * time.Second,
				},
			},
			Producer: rabbitmqqueue.ProducerConfig{
				Limits: rabbitmqqueue.DefaultLimits(), MaxOutstanding: 256,
				PublishTimeout: 5 * time.Second,
			},
			Consumer: rabbitmqqueue.ConsumerConfig{
				Limits: rabbitmqqueue.DefaultLimits(),
				Queue:  rabbitmqqueue.QueueReference{Name: "jobs", Type: rabbitmqqueue.QueueQuorum},
				Name:   "jobs-worker", Prefetch: 32, Concurrency: 8,
				HandlerTimeout: time.Minute, MaxRequeues: 1,
				Failure: rabbitmqqueue.Reject(false),
			},
			MessageID: func(core.TaskMessage) (string, error) { return "stable-job-id", nil },
		}),
		rabbitmq.WithQueue("jobs"),
		rabbitmq.WithTag("jobs-worker"),
		rabbitmq.WithExchangeName("jobs.events"),
		rabbitmq.WithExchangeType(rabbitmq.ExchangeTopic),
		rabbitmq.WithRoutingKey("jobs.created"),
	)
}

type Option deprecated

type Option func(*options)

Option preserves the released worker configuration surface.

Deprecated: use successor.Option.

func WithAddr deprecated

func WithAddr(value string) Option

WithAddr retains the legacy address option; native RabbitMQ connections use NativeConfig.

Deprecated: use successor.WithAddr.

func WithAutoAck deprecated

func WithAutoAck(value bool) Option

WithAutoAck forwards acknowledgement policy; the native adapter rejects automatic acknowledgement.

Deprecated: use successor.WithAutoAck.

func WithDeadLetter deprecated

func WithDeadLetter(value DeadLetterConfig) Option

WithDeadLetter forwards terminal destination and delivery-attempt policy.

Deprecated: use successor.WithDeadLetter.

func WithExchangeName deprecated

func WithExchangeName(value string) Option

WithExchangeName forwards the infrastructure-owned exchange name.

Deprecated: use successor.WithExchangeName.

func WithExchangeType deprecated

func WithExchangeType(value string) Option

WithExchangeType forwards exchange kind; the native adapter accepts direct or topic.

Deprecated: use successor.WithExchangeType.

func WithLogger deprecated

func WithLogger(value queue.Logger) Option

WithLogger forwards the borrowed logging implementation.

Deprecated: use successor.WithLogger.

func WithNativeConfig deprecated

func WithNativeConfig(value NativeConfig) Option

WithNativeConfig forwards explicit native connection and resource policy.

Deprecated: use successor.WithNativeConfig.

func WithPublishTimeout deprecated

func WithPublishTimeout(value time.Duration) Option

WithPublishTimeout forwards the per-publish time bound.

Deprecated: use successor.WithPublishTimeout.

func WithQueue deprecated

func WithQueue(value string) Option

WithQueue forwards the logical queue name.

Deprecated: use successor.WithQueue.

func WithReconnectConfig deprecated

func WithReconnectConfig(value ReconnectConfig) Option

WithReconnectConfig retains legacy configuration; NativeConfig owns runtime recovery.

Deprecated: use successor.WithReconnectConfig.

func WithRequestTimeout deprecated

func WithRequestTimeout(value time.Duration) Option

WithRequestTimeout forwards the request wait duration.

Deprecated: use successor.WithRequestTimeout.

func WithRoutingKey deprecated

func WithRoutingKey(value string) Option

WithRoutingKey forwards the exchange route.

Deprecated: use successor.WithRoutingKey.

func WithRunFunc deprecated

func WithRunFunc(value func(context.Context, core.TaskMessage) error) Option

WithRunFunc forwards synchronous handler code that must honor its context.

Deprecated: use successor.WithRunFunc.

func WithTag deprecated

func WithTag(value string) Option

WithTag forwards the consumer name.

Deprecated: use successor.WithTag.

type ReconnectConfig deprecated

type ReconnectConfig struct {
	// MaxRetries is retained for source compatibility.
	MaxRetries int
	// InitialDelay is retained for source compatibility.
	InitialDelay time.Duration
	// MaxDelay is retained for source compatibility.
	MaxDelay time.Duration
}

ReconnectConfig preserves the released source-compatible recovery options. NativeConfig.Connection.Recovery owns runtime recovery.

Deprecated: use successor.ReconnectConfig.

type Worker deprecated

type Worker struct {
	// contains filtered or unexported fields
}

Worker preserves the released queue worker API while delegating all runtime ownership and behavior to the target-oriented successor.

Deprecated: use successor.Worker.

func NewWorker deprecated

func NewWorker(options ...Option) *Worker

NewWorker constructs the successor worker and panics on error.

Deprecated: use successor.NewWorker.

func NewWorkerE deprecated

func NewWorkerE(optionValues ...Option) (*Worker, error)

NewWorkerE constructs the successor worker and returns its construction error.

Deprecated: use successor.NewWorkerE.

Example
package main

import (
	"errors"
	"fmt"

	queue "github.com/faustbrian/go-queue"

	rabbitmq "github.com/faustbrian/go-queue/rabbitmq"
)

func main() {
	worker, err := rabbitmq.NewWorkerE()
	fmt.Println(worker == nil, errors.Is(err, queue.ErrInvalidConfiguration))

}
Output:
true true

func (*Worker) BackendName

func (*Worker) BackendName() string

BackendName identifies RabbitMQ in lifecycle events.

func (*Worker) Queue

func (worker *Worker) Queue(task core.TaskMessage) error

Queue publishes one mandatory persistent task and waits for broker confirmation.

func (*Worker) QueueName

func (worker *Worker) QueueName() string

QueueName returns the configured RabbitMQ queue.

func (*Worker) Request

func (worker *Worker) Request() (core.TaskMessage, error)

Request returns one decoded task from the bounded delivery bridge.

func (*Worker) Run

func (worker *Worker) Run(ctx context.Context, task core.TaskMessage) error

Run executes the configured go-queue handler.

func (*Worker) Shutdown

func (worker *Worker) Shutdown() error

Shutdown closes consumer and producer resources once.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL