publisher

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: 4 Imported by: 3

Documentation

Overview

Package publisher provides a high-level publisher for sending messages to RabbitMQ with support for middleware and confirmation modes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPublisherIsNotInitialized is returned when the publisher has not been initialized.
	ErrPublisherIsNotInitialized = errors.New("publisher is not initialized")
)

Functions

This section is empty.

Types

type Middleware

type Middleware func(next RoundTripper) RoundTripper

Middleware is a function that wraps a RoundTripper, enabling request processing chains.

func PersistentMode

func PersistentMode() Middleware

PersistentMode is a middleware that sets message delivery mode to persistent. This ensures messages are durably stored by the broker.

type Option

type Option func(publisher *Publisher)

Option is a function that configures a Publisher instance.

func WithMiddlewares

func WithMiddlewares(middlewares ...Middleware) Option

WithMiddlewares sets the middleware chain for the publisher. Middlewares are executed in the order they are provided.

type Publisher

type Publisher struct {
	Exchange    string
	RoutingKey  string
	Middlewares []Middleware
	// contains filtered or unexported fields
}

Publisher represents a message publisher with configurable exchange, routing key, and middleware support.

func New

func New(exchange string, routingKey string, opts ...Option) *Publisher

New creates a new Publisher with the specified exchange and routing key. Optional configuration can be provided using Option functions.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, msg *amqp.Publishing) error

Publish sends a message to the configured exchange and routing key. Returns an error if the publisher is not initialized or the publish operation fails.

func (*Publisher) PublishTo

func (p *Publisher) PublishTo(ctx context.Context, exchange string, routingKey string, msg *amqp.Publishing) error

PublishTo sends a message to the specified exchange and routing key, overriding the publisher's default configuration.

func (*Publisher) SetRoundTripper

func (p *Publisher) SetRoundTripper(rootRoundTripper RoundTripper)

SetRoundTripper configures the round tripper with middleware chain. This method must be called before the publisher can be used.

type RoundTripper

type RoundTripper interface {
	Publish(ctx context.Context, exchange string, routingKey string, msg *amqp.Publishing) error
}

RoundTripper defines the interface for publishing messages to RabbitMQ.

type RoundTripperFunc

type RoundTripperFunc func(ctx context.Context, exchange string, routingKey string, msg *amqp.Publishing) error

RoundTripperFunc is an adapter that allows regular functions to be used as RoundTripper.

func (RoundTripperFunc) Publish

func (f RoundTripperFunc) Publish(ctx context.Context, exchange string, routingKey string, msg *amqp.Publishing) error

Publish implements the RoundTripper interface.

Jump to

Keyboard shortcuts

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