pub struct RetryTransport<T> { /* private fields */ }api only.Expand description
A Transport that retries transient failures.
API gateways in front of TM Forum deployments rate-limit and occasionally
drop connections. RetryTransport wraps any Transport and re-issues a
request when the failure is one worth retrying, backing off exponentially
with jitter and honouring Retry-After.
use std::time::Duration;
use rutmf::api::{RetryPolicy, RetryTransport, Transport};
let transport = RetryTransport::new(
inner,
RetryPolicy::default().max_retries(5).base_delay(Duration::from_millis(200)),
);§Which requests are retried
Only idempotent ones: GET, HEAD, PUT and DELETE. POST is not
idempotent — re-sending one could create a duplicate resource — so it is
passed through untouched even when the failure looks transient.
PATCH is not retried either, and that is deliberate rather than an
oversight. Three of the four v5 PATCH flavours are merges, which happen to
be idempotent; the RFC 6902 operation list is not, because add on an array
inserts, so replaying one appends a second copy. The method does not say
which flavour it is carrying, so it is treated as the unsafe case.
§Sleeping
Backing off requires a timer, and the domain model deliberately has no
runtime dependency. So the wait is a seam: Sleeper is a trait, the
transport-reqwest feature supplies a tokio implementation as the
default, and RetryTransport::with_sleeper takes any other.
Without a Sleeper there is no backoff, only immediate re-sending — which
against a rate-limited gateway is worse than not retrying at all. That is
why RetryTransport::new exists only when a default sleeper does.
Implementations§
Source§impl<T> RetryTransport<T>
impl<T> RetryTransport<T>
Sourcepub fn new(inner: T, policy: RetryPolicy) -> Self
Available on crate feature transport-reqwest only.
pub fn new(inner: T, policy: RetryPolicy) -> Self
transport-reqwest only.Wraps inner with policy, sleeping on tokio.
Sourcepub fn with_defaults(inner: T) -> Self
Available on crate feature transport-reqwest only.
pub fn with_defaults(inner: T) -> Self
transport-reqwest only.Wraps inner with the default policy, sleeping on tokio.
Source§impl<T> RetryTransport<T>
impl<T> RetryTransport<T>
Sourcepub fn with_sleeper(
inner: T,
policy: RetryPolicy,
sleeper: impl Sleeper,
) -> Self
pub fn with_sleeper( inner: T, policy: RetryPolicy, sleeper: impl Sleeper, ) -> Self
Wraps inner with policy, waiting through sleeper.
Use this to drive backoff from a runtime other than tokio, or from a
fake clock in a test.