Table of Contents

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 uint

The maximum number of retry attempts.

maxWait TimeSpan

The maximum amount of time to wait between retries.

useJitter bool

Whether 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 uint

The maximum number of retry attempts.

baseExponent uint

The base exponent to start the backoff calculation (CurrentExponent(currentRetryCount) = baseExponent + currentRetryCount).

maxWait TimeSpan

The maximum amount of time to wait between retries.

useJitter bool

Whether 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 uint

The number of times the current operation has been attempted.

lastException Exception

The exception that prompted this retry policy check.

retryDelay TimeSpan

Set 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
    }
}