Class ExponentialBackoffRetryPolicy
- Namespace
- Azure.Iot.Operations.Protocol.Retry
- Assembly
- Azure.Iot.Operations.Protocol.dll
Implements Binary Exponential Backoff (BEB) retry policy as follows: CurrentExponent = min(MaxExponent, baseExponent + currentRetryCount) RetryDelay = min(pow(2, CurrentExponent), maxWait) milliseconds
public class ExponentialBackoffRetryPolicy : IRetryPolicy
- Inheritance
-
ExponentialBackoffRetryPolicy
- Implements
- Inherited Members
Constructors
ExponentialBackoffRetryPolicy(uint, TimeSpan, bool)
Creates an instance of this class with a default base exponent equals 6.
public ExponentialBackoffRetryPolicy(uint maxRetries, TimeSpan maxWait, bool useJitter = true)
Parameters
maxRetries
uintThe maximum number of retry attempts.
maxWait
TimeSpanThe maximum amount of time to wait between retries.
useJitter
boolWhether to add a small, random adjustment to the retry delay to avoid synchronicity in clients retrying.
ExponentialBackoffRetryPolicy(uint, uint, TimeSpan, bool)
Creates an instance of this class.
public ExponentialBackoffRetryPolicy(uint maxRetries, uint baseExponent, TimeSpan maxWait, bool useJitter = true)
Parameters
maxRetries
uintThe maximum number of retry attempts.
baseExponent
uintThe base exponent to start the backoff calculation (CurrentExponent(currentRetryCount) = baseExponent + currentRetryCount).
maxWait
TimeSpanThe maximum amount of time to wait between retries.
useJitter
boolWhether to add a small, random adjustment to the retry delay to avoid synchronicity in clients retrying.
Methods
ShouldRetry(uint, Exception?, out TimeSpan)
Method called by the client when an operation fails to determine if a retry should be attempted, and how long to wait until retrying the operation.
public bool ShouldRetry(uint currentRetryCount, Exception? lastException, out TimeSpan retryDelay)
Parameters
currentRetryCount
uintThe number of times the current operation has been attempted.
lastException
ExceptionThe exception that prompted this retry policy check.
retryDelay
TimeSpanSet this to the desired time to delay before the next attempt.
Returns
- bool
True if the operation should be retried; otherwise false.
Examples
class CustomRetryPolicy : IRetryPolicy
{
public bool ShouldRetry(uint currentRetryCount, Exception lastException, out TimeSpan retryDelay)
{
// Add custom logic as needed upon determining if it should retry and set the retryDelay out parameter
}
}