Documentation
¶
Overview ¶
Package consumer provides a high-level consumer for receiving messages from RabbitMQ with support for concurrency, middleware, and retry policies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDeliveryAlreadyHandled is returned when attempting to handle an already processed delivery. ErrDeliveryAlreadyHandled = errors.New("delivery already handled") )
Functions ¶
This section is empty.
Types ¶
type Consumer ¶
type Consumer struct {
Queue string
Name string
Concurrency int
PrefetchCount int
Middlewares []Middleware
RetryPolicy *retry.Policy
Closer Closer
// contains filtered or unexported fields
}
Consumer represents a message consumer with configurable queue, concurrency, and middleware support.
type Delivery ¶
type Delivery struct {
// contains filtered or unexported fields
}
Delivery wraps an AMQP delivery with acknowledgment and retry capabilities.
func NewDelivery ¶
NewDelivery creates a new Delivery instance with the specified configuration.
func (*Delivery) Ack ¶
Ack Acknowledges the delivery, marking it as successfully processed and removing it from the queue. The delivery must be acknowledged exactly once. Subsequent calls will return ErrDeliveryAlreadyHandled. Returns an error if the broker fails to acknowledge the delivery (e.g., connection issues).
After Ack returns (either successfully or with an error), the delivery is considered handled and no further acknowledgment operations should be performed on it.
func (*Delivery) Nack ¶
Nack negatively acknowledges the delivery, indicating processing failed. The requeue parameter controls whether the message is returned to the queue immediately (true) or sent to the dead-letter queue (false). Returns an error if the delivery has already been handled or if the broker rejects the nack.
After Nack returns (either successfully or with an error), the delivery is considered handled and no further acknowledgment operations should be performed on it.
func (*Delivery) Retry ¶
Retry attempts to redeliver the message according to the configured retry policy. If a retry policy is configured, the message is published to a retry queue with a delay. If no retry policy is configured, the message is requeued via Nack.
Returns ErrDeliveryAlreadyHandled if the delivery has already been processed. Returns an error if the retry operation fails (e.g., publishing to retry queue fails).
Note: When Retry returns an error, the message has NOT been acknowledged and will need to be handled again by the caller.
type Donner ¶
type Donner interface {
Done()
}
Donner defines an interface for signaling completion of delivery processing.
type HandlerFunc ¶
HandlerFunc is an adapter that allows regular functions to be used as Handler.
type Middleware ¶
Middleware is a function that wraps a Handler, enabling request processing chains.
type Option ¶
type Option func(c *Consumer)
Option is a function that configures a Consumer instance.
func WithCloser ¶
WithCloser sets the resource closer for the consumer.
func WithConcurrency ¶
WithConcurrency sets the number of concurrent workers processing messages.
func WithMiddlewares ¶
func WithMiddlewares(middlewares ...Middleware) Option
WithMiddlewares sets the middleware chain for the consumer. Middlewares are executed in the order they are provided.
func WithPrefetchCount ¶
WithPrefetchCount sets the maximum number of unacknowledged messages.
func WithRetryPolicy ¶
WithRetryPolicy configures the retry policy for failed message processing.