rabbitmq

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package rabbitmq provides a RabbitMQ client, which is suitable for sending and receiving messages. It is expexted to work with a single queue.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUninitialized is returned when the message queue connection is not initialized.
	ErrUninitialized = errors.New("rabbitmq is not initialized (initialize connection first?)")
	// ErrFatal is returned when an unexpected internal error occurs.
	ErrFatal = errors.New("fatal error")
)

Functions

This section is empty.

Types

type ClientType

type ClientType int

ClientType represents a RabbitMQ client type.

const (
	// FullClient matches a full client configuration.
	FullClient ClientType = iota
	// ProducerOnly matches a client configuration with producer-only fields.
	ProducerOnly
	// ConsumerOnly matches a client configuration with consumer-only fields.
	ConsumerOnly
)

type Logger

type Logger interface {
	// Info logs a message with level Info on the standard logger.
	Info(ctx context.Context, msg string, args ...any)
	// Debug logs a message with level Debug on the standard logger.
	Debug(ctx context.Context, msg string, args ...any)
	// Warn logs a message with level Warn on the standard logger.
	Warn(ctx context.Context, msg string, args ...any)
	// Error logs a message with level Error on the standard logger.
	Error(ctx context.Context, msg string, args ...any)
}

Logger represents an interface of logger visible to the app.

type RabbitMQ

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

RabbitMQ represents a RabbitMQ client.

func NewRabbitMQ

func NewRabbitMQ(logger Logger, cfg map[string]any, typ ClientType) (*RabbitMQ, error)

NewRabbitMQ creates a new RabbitMQ client. Supports partial configuration for different client types: consumer, producer or full client. Unknown client type defaults to FullClient.

func (*RabbitMQ) Close

func (r *RabbitMQ) Close(_ context.Context) error

Close the connection to the message queue.

func (*RabbitMQ) Connect

func (r *RabbitMQ) Connect(_ context.Context) error

Connect to the message queue.

func (*RabbitMQ) Consume

func (r *RabbitMQ) Consume(ctx context.Context) (<-chan []byte, <-chan error)

Consume consumes messages from the message queue using retry logic and operation timeout. The methods abstracts the logic of consuming messages from the message queue.

func (*RabbitMQ) Produce

func (r *RabbitMQ) Produce(ctx context.Context, payload []byte) error

Produce sends a message to the message queue using retry logic and operation timeout.

Jump to

Keyboard shortcuts

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