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§
- Exponential
Backoff - Exponential backoff with configurable multiplier.
- Exponential
Random Backoff - Exponential backoff with randomization to prevent thundering herd.
- Fixed
Interval - Fixed interval backoff - returns the same duration for every retry.
- FnInterval
- Function-based interval implementation.
- Retry
- A Tower
Servicethat retries failed requests. - Retry
Config - Configuration for the retry middleware.
- Retry
Config Builder - Builder for
RetryConfig. - Retry
Layer - A Tower
Layerthat applies retry logic to a service. - Retry
Policy - Policy for retry behavior.
Enums§
- Retry
Event - Events emitted by the retry middleware.
Traits§
- Interval
Function - Abstraction for computing retry intervals.
Type Aliases§
- Retry
Predicate - Determines whether an error should be retried.