topology

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package topology provides types and functions for defining RabbitMQ topology including exchanges, queues, and bindings.

Index

Constants

View Source
const (
	// DLXName is the name of the default dead-letter exchange.
	DLXName = "default-dead-letter"
	// DLQSuffix is the suffix for dead-letter queues.
	DLQSuffix = "DLQ"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding struct {
	ExchangeName string
	QueueName    string
	RoutingKey   string
	Args         amqp.Table
}

Binding represents a connection between an exchange and a queue.

func NewBinding

func NewBinding(exchangeName string, queueName string, routingKey string) *Binding

NewBinding creates a new binding between an exchange and a queue.

type Declarations

type Declarations struct {
	Exchanges []*Exchange
	Queues    []*Queue
	Bindings  []*Binding
}

Declarations represents a complete topology configuration.

func Compile

func Compile(cfg Declarations) Declarations

Compile processes the declarations and automatically creates dead-letter queues, retry queues, and their associated bindings based on the configuration.

func New

func New(opts ...DeclarationsOption) Declarations

New creates a new Declarations instance with the specified options.

type DeclarationsOption

type DeclarationsOption func(d *Declarations)

DeclarationsOption is a function that configures a Declarations instance.

func WithBinding

func WithBinding(exchangeName string, queueName string, routingKey string) DeclarationsOption

WithBinding adds a binding between an exchange and a queue.

func WithDirectExchange

func WithDirectExchange(name string) DeclarationsOption

WithDirectExchange adds a direct exchange to the declarations.

func WithFanoutExchange

func WithFanoutExchange(name string) DeclarationsOption

WithFanoutExchange adds a fanout exchange to the declarations.

func WithQueue

func WithQueue(name string, opts ...QueueOption) DeclarationsOption

WithQueue adds a queue to the declarations.

func WithTopicExchange

func WithTopicExchange(name string) DeclarationsOption

WithTopicExchange adds a topic exchange to the declarations.

type Exchange

type Exchange struct {
	Name string
	Type string
	Args amqp.Table
}

Exchange represents a RabbitMQ exchange configuration.

func NewDirectExchange

func NewDirectExchange(name string) *Exchange

NewDirectExchange creates a new direct exchange.

func NewFanoutExchange

func NewFanoutExchange(name string) *Exchange

NewFanoutExchange creates a new fanout exchange.

func NewTopicExchange

func NewTopicExchange(name string) *Exchange

NewTopicExchange creates a new topic exchange.

type Queue

type Queue struct {
	Name        string
	DLQ         bool
	Durable     bool
	AutoDelete  bool
	RetryPolicy *retry.Policy
	Args        amqp.Table
}

Queue represents a RabbitMQ queue configuration.

func NewQueue

func NewQueue(name string, opts ...QueueOption) *Queue

NewQueue creates a new queue with the specified name and optional configuration. By default, queues are created as durable.

type QueueOption

type QueueOption func(q *Queue)

QueueOption is a function that configures a Queue instance.

func WithAutoDelete

func WithAutoDelete(value bool) QueueOption

WithAutoDelete configures whether the queue is deleted when no longer in use.

func WithDLQ

func WithDLQ(value bool) QueueOption

WithDLQ configures whether the queue is a dead-letter queue.

func WithDurable

func WithDurable(value bool) QueueOption

WithDurable configures whether the queue survives broker restarts.

func WithQueueArg

func WithQueueArg(key string, value any) QueueOption

WithQueueArg sets a custom argument for the queue.

func WithRetryPolicy

func WithRetryPolicy(policy retry.Policy) QueueOption

WithRetryPolicy configures the retry policy for the queue.

Jump to

Keyboard shortcuts

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