Skip to main content

Crate tower_retry_plus

Crate tower_retry_plus 

Source
Expand description

Enhanced retry middleware for Tower services.

This crate provides advanced retry functionality beyond Tower’s built-in retry, with flexible backoff strategies, retry predicates, and comprehensive event system.

§Features

  • IntervalFunction abstraction: Pluggable backoff strategies
    • Fixed interval
    • Exponential backoff with configurable multiplier
    • Exponential random backoff with randomization factor
    • Custom function-based backoff
  • Retry predicates: Control which errors should be retried
  • Event system: Observability through retry events
  • Flexible configuration: Builder API with sensible defaults

§Examples

use tower_retry_plus::RetryConfig;
use tower::ServiceBuilder;
use std::time::Duration;

// Create retry configuration with exponential backoff
let retry_config: RetryConfig<MyError> = RetryConfig::builder()
    .max_attempts(5)
    .exponential_backoff(Duration::from_millis(100))
    .on_retry(|attempt, delay| {
        println!("Retry attempt {} after {:?}", attempt, delay);
    })
    .build();

// Apply to a service
let service = ServiceBuilder::new()
    .layer(retry_config.layer())
    .service(tower::service_fn(|req: String| async move {
        Ok::<_, MyError>(format!("Response: {}", req))
    }));

Structs§

ExponentialBackoff
Exponential backoff with configurable multiplier.
ExponentialRandomBackoff
Exponential backoff with randomization to prevent thundering herd.
FixedInterval
Fixed interval backoff - returns the same duration for every retry.
FnInterval
Function-based interval implementation.
Retry
A Tower Service that retries failed requests.
RetryConfig
Configuration for the retry middleware.
RetryConfigBuilder
Builder for RetryConfig.
RetryLayer
A Tower Layer that applies retry logic to a service.
RetryPolicy
Policy for retry behavior.

Enums§

RetryEvent
Events emitted by the retry middleware.

Traits§

IntervalFunction
Abstraction for computing retry intervals.

Type Aliases§

RetryPredicate
Determines whether an error should be retried.