retry

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: 6 Imported by: 1

Documentation

Overview

Package retry provides retry policies for failed message processing in consumers.

Index

Constants

View Source
const (
	// Forever represents unlimited retry attempts.
	Forever = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Policy

type Policy struct {
	// Retries is a list of retry steps to attempt.
	Retries []Retry
	// FinallyMoveToDlq specifies whether to move the message to DLQ after all retries are exhausted.
	FinallyMoveToDlq bool
}

Policy defines a complete retry configuration with multiple retry steps.

func NewPolicy

func NewPolicy(finallyMoveToDlq bool, retries ...Retry) Policy

NewPolicy creates a new retry policy with the specified configuration.

type Publisher

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

Publisher defines an interface for publishing messages with confirmation.

type Retry

type Retry struct {
	Delay       time.Duration
	MaxAttempts int
}

Retry defines a single retry step with a delay and maximum attempt count.

func ForeverWithDelay

func ForeverWithDelay(delay time.Duration) Retry

ForeverWithDelay creates a retry step that retries indefinitely with the specified delay.

func WithDelay

func WithDelay(delay time.Duration, maxTries int) Retry

WithDelay creates a retry step with a specific delay and maximum attempts.

func (Retry) QueueName

func (r Retry) QueueName(originalQueue string) string

QueueName generates the queue name for this retry step.

type Retryer

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

Retryer manages message retry logic according to a configured policy.

func NewRetryer

func NewRetryer(originalQueue string, policy Policy, pub Publisher) *Retryer

NewRetryer creates a new Retryer with the specified configuration.

func (*Retryer) Do

func (r *Retryer) Do(delivery *amqp.Delivery) error

Do processes a failed delivery according to the retry policy. Returns an error if publishing or acknowledgment fails.

Jump to

Keyboard shortcuts

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