Package com.azure.core.http.policy
Class RetryOptions
java.lang.Object
com.azure.core.http.policy.RetryOptions
The
RetryOptions class provides configuration options for retry strategies. It supports both
ExponentialBackoffOptions and FixedDelayOptions.
This class is useful when you need to customize the behavior of retries in the HTTP pipeline. It allows you to specify the type of retry strategy and its options.
Here's a code sample of how to use this class:
In these examples, RetryOptions is created with either ExponentialBackoffOptions or
FixedDelayOptions. These options can then be used to configure a retry policy in the HTTP pipeline.
// Using ExponentialBackoffOptions
ExponentialBackoffOptions exponentialOptions = new ExponentialBackoffOptions()
.setMaxRetries(5)
.setBaseDelay(Duration.ofSeconds(1))
.setMaxDelay(Duration.ofSeconds(10));
RetryOptions retryOptions = new RetryOptions(exponentialOptions);
// Using FixedDelayOptions
FixedDelayOptions fixedOptions = new FixedDelayOptions(3, Duration.ofSeconds(1));
RetryOptions retryOptions = new RetryOptions(fixedOptions);
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRetryOptions(ExponentialBackoffOptions exponentialBackoffOptions) Creates a new instance that usesExponentialBackoffOptions.RetryOptions(FixedDelayOptions fixedDelayOptions) Creates a new instance that usesFixedDelayOptions. -
Method Summary
Modifier and TypeMethodDescriptionGets the configuration for exponential backoff if configured.Gets the configuration for exponential backoff if configured.Gets the predicate that determines if a retry should be attempted.setShouldRetryCondition(Predicate<RequestRetryCondition> shouldRetryCondition) Sets the predicate that determines if a retry should be attempted.
-
Constructor Details
-
RetryOptions
Creates a new instance that usesExponentialBackoffOptions.- Parameters:
exponentialBackoffOptions- TheExponentialBackoffOptions.
-
RetryOptions
Creates a new instance that usesFixedDelayOptions.- Parameters:
fixedDelayOptions- TheFixedDelayOptions.
-
-
Method Details
-
getExponentialBackoffOptions
Gets the configuration for exponential backoff if configured.- Returns:
- The
ExponentialBackoffOptions.
-
getFixedDelayOptions
Gets the configuration for exponential backoff if configured.- Returns:
- The
FixedDelayOptions.
-
getShouldRetryCondition
Gets the predicate that determines if a retry should be attempted.If null, the default behavior is to retry HTTP responses with status codes 408, 429, and any 500 status code that isn't 501 or 505. And to retry any
Exception.- Returns:
- The predicate that determines if a retry should be attempted.
-
setShouldRetryCondition
Sets the predicate that determines if a retry should be attempted.If null, the default behavior is to retry HTTP responses with status codes 408, 429, and any 500 status code that isn't 501 or 505. And to retry any
Exception.- Parameters:
shouldRetryCondition- The predicate that determines if a retry should be attempted for the givenHttpResponse.- Returns:
- The updated
RetryOptionsobject.
-