Expand description
Circuit breaker state machine and retry middleware.
§Circuit breaker
CircuitBreaker tracks per-backend failure counts and transitions through
three states:
- Closed — the backend is healthy; failures are counted. When the count
reaches
failure_thresholdthe breaker moves to Open. - Open — the backend is considered unhealthy; all requests are rejected
immediately (no TCP connection is attempted). After
recoveryseconds the breaker moves to HalfOpen. - HalfOpen — one probe request is let through. On success the breaker closes; on failure it re-opens and the recovery timer resets.
§Retry middleware
RetryLayer wraps any Application and re-dispatches the request when
the inner app returns one of the configured status codes (default: 502, 503,
504) up to max_retries additional times.
§Example
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::circuit_breaker::RetryLayer;
use rust_web_server::middleware::WithMiddleware;
let app = WithMiddleware::new(App::new())
.wrap(RetryLayer::new().max_retries(2));Structs§
- Circuit
Breaker - Per-backend circuit breaker.
- Retry
Layer - Retry middleware.
Enums§
- Breaker
State - Current state of a single backend’s circuit breaker.
Functions§
- global
- Return the process-wide default circuit breaker (threshold=5, recovery=30 s).