Documentation ¶
Index ¶
Constants ¶
const ( DefaultReconnectWait = 5 * time.Second DefaultReopenChannelWait = 2 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
func NewConsumer ¶
NewConsumer creates a Consumer that synchronously connects/opens a channel to RabbitMQ at the given URI. If the consumer was able to connect/open a channel it will automatically re-connect and re-open connection and channel if they fail. A consumer holds on to one connection and one channel. A consumer can be used to consume multiple times and from multiple goroutines.
func (*Consumer) Cancel ¶
Cancel consuming messages for given consumer. The consumer tag is returned by Consume(). It is safe to call this method multiple times and in multiple goroutines.
func (*Consumer) Close ¶
Close connection and channel. A new consumer needs to be created in order to consume again after closing it. It is safe to call this method multiple times and in multiple goroutines.
func (*Consumer) Consume ¶
Consume registers the consumer to receive messages from given queue. Consume synchronously declares and registers a consumer to the queue. Once registered it will return the consumer identifier and nil error. receive will be called for every message. Pass the consumer identifier to Cancel() to stop consuming messages. Consume will re-consume if the connection or channel close only if it returned successfully at first. Consume can be called multiple times and from multiple goroutines.
type Option ¶
type Option func(*consumerOptions)
An Option configures consumer options.
func WithConnectionName ¶
WithConnectionName sets the `connection_name` property on the RabbitMQ connection. This can aid in observing/debugging connections (RabbitMQ management/CLI).
func WithConsumerTagPrefix ¶
WithConsumerTagPrefix sets the prefix to the auto-generated consumer tag. The consumer tag is returned by Consume(). This can aid in observing/debugging consumers on a channel (RabbitMQ management/CLI).
func WithLogger ¶
WithLogger sets the logger to be used by the consumer. The consumer will log using slog.Default() by default.
func WithReconnectWait ¶
WithReconnectWait sets the duration to wait after a failed attempt to connect to RabbitMQ.
func WithReopenChannelWait ¶
WithReopenChannelWait sets the duration to wait after a failed attempt to open a channel on a RabbitMQ connection.