rabbitmq

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChannelPoolSize = 5
)

Variables

This section is empty.

Functions

func NewPublisher

func NewPublisher(
	opts ...publisherOpts.PublisherOptionFunc,
) publisher.Publisher

NewPublisher creates a new instance of the publisher.Publisher interface using the provided options. It returns a publisher.Publisher implementation that utilizes RabbitMQ as the underlying message broker.

The function accepts a variadic parameter `opts` of type `publisherOpts.PublisherOptionFunc`, which allows the caller to provide custom configuration options for the publisher.

Example usage:

publisher := NewPublisher(
				publisherOpts.PublisherPlatformRabbitMQ,
				publisherOpts.WithRabbitMQPublisherConfig(&publisherOpts.RabbitMQPublisherConfig{
					Conn:                     rmqConn,
					PublisherChannelPoolSize: 5,
					}),
				publisherOpts.WithPublisherID("publisher_id"),
				publisherOpts.WithMiddlewares(
					middleware.HelloWorldMiddlewareExecuteBeforePublisher(),
					middleware.HelloWorldMiddlewareExecuteAfterPublisher(),
				),

)

The returned publisher can be used to publish messages to the configured RabbitMQ exchange and routing key.

Types

type ChannelPool

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

ChannelPool represents a pool of AMQP channels used for publishing messages. It provides a way to manage and reuse AMQP channels efficiently.

func NewChannelPool

func NewChannelPool(conn *amqp.Connection, maxSize int) *ChannelPool

NewChannelPool creates a new ChannelPool instance. It takes an AMQP connection and the maximum size of the pool as parameters. It returns a pointer to the newly created ChannelPool.

func (*ChannelPool) Close

func (cp *ChannelPool) Close() (err error)

Close closes the ChannelPool and all its associated channels. It returns an error if there was an error closing any of the channels.

func (*ChannelPool) Get

func (cp *ChannelPool) Get() (*amqp.Channel, error)

Get returns a channel from the pool. If there are available channels in the pool, it returns one of them. Otherwise, it creates a new channel from the underlying connection and returns it.

func (*ChannelPool) Return

func (cp *ChannelPool) Return(ch *amqp.Channel)

Return returns a channel back to the channel pool. If the pool is full, the channel is closed.

Jump to

Keyboard shortcuts

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