pub struct BackoffPolicy {
pub max_attempts: Option<u32>,
pub backoff: Backoff,
}Expand description
The built-in ReconnectPolicy: a Backoff curve plus an optional cap on
consecutive attempts.
A dropped connection is the normal case, not the exceptional one: brokers are restarted for upgrades, failed over, and partitioned from their clients by the network in between. The default therefore retries forever, on the theory that a worker process which outlives its broker’s restart is worth more than one which exits and waits for a supervisor.
use queuey_rabbitmq::BackoffPolicy;
// Give up after ten tries instead of retrying forever.
let policy = BackoffPolicy::default().max_attempts(Some(10));
assert_eq!(policy.max_attempts, Some(10));Set RabbitMqOptions::reconnect to
None to turn reconnection off entirely and get the original fail-fast
behaviour back.
Fields§
§max_attempts: Option<u32>How many consecutive attempts to make before giving up, or None to
keep trying indefinitely.
Defaults to None. The count is of consecutive failures: it resets
the moment a connection succeeds, so a process that reconnects once an
hour for a year never exhausts a limit of three. Some(0) never
reconnects at all, which is RabbitMqOptions::reconnect(None) the
long way round.
backoff: BackoffDelay between attempts, as a function of how many have failed.
Defaults to exponential with full jitter: 500ms base, doubling, capped at 30 seconds. Jitter matters more here than in a job backoff: every worker in a fleet loses its connection at the same instant when a broker goes down, and an unjittered backoff would have all of them knock on the door in lockstep for as long as the outage lasts.
Implementations§
Trait Implementations§
Source§impl Clone for BackoffPolicy
impl Clone for BackoffPolicy
Source§fn clone(&self) -> BackoffPolicy
fn clone(&self) -> BackoffPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BackoffPolicy
impl Debug for BackoffPolicy
Source§impl Default for BackoffPolicy
impl Default for BackoffPolicy
Source§impl ReconnectPolicy for BackoffPolicy
impl ReconnectPolicy for BackoffPolicy
Source§fn next_delay(&self, attempt: Attempt<'_>) -> Option<Duration>
fn next_delay(&self, attempt: Attempt<'_>) -> Option<Duration>
The first attempt after a drop is immediate; the rest follow the curve.
A failover is often complete in the time it took the client to notice, so
waiting out a backoff before even trying would add that delay to the
common case. Backoff::delay_for takes the 1-based attempt that just
failed, which is exactly the failure count.