你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
RetryOptions Class
- java.
lang. Object - com.
azure. core. http. policy. RetryOptions
- com.
public class 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);
Constructor Summary
Constructor | Description |
---|---|
RetryOptions(ExponentialBackoffOptions exponentialBackoffOptions) |
Creates a new instance that uses ExponentialBackoffOptions. |
RetryOptions(FixedDelayOptions fixedDelayOptions) |
Creates a new instance that uses FixedDelayOptions. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Exponential |
getExponentialBackoffOptions()
Gets the configuration for exponential backoff if configured. |
Fixed |
getFixedDelayOptions()
Gets the configuration for exponential backoff if configured. |
Predicate<Request |
getShouldRetryCondition()
Gets the predicate that determines if a retry should be attempted. |
Retry |
setShouldRetryCondition(Predicate<RequestRetryCondition> shouldRetryCondition)
Sets the predicate that determines if a retry should be attempted. |
Methods inherited from java.lang.Object
Constructor Details
RetryOptions
public RetryOptions(ExponentialBackoffOptions exponentialBackoffOptions)
Creates a new instance that uses ExponentialBackoffOptions.
Parameters:
RetryOptions
public RetryOptions(FixedDelayOptions fixedDelayOptions)
Creates a new instance that uses FixedDelayOptions.
Parameters:
Method Details
getExponentialBackoffOptions
public ExponentialBackoffOptions getExponentialBackoffOptions()
Gets the configuration for exponential backoff if configured.
Returns:
getFixedDelayOptions
public FixedDelayOptions getFixedDelayOptions()
Gets the configuration for exponential backoff if configured.
Returns:
getShouldRetryCondition
public Predicate
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:
setShouldRetryCondition
public RetryOptions setShouldRetryCondition(Predicate
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:
Returns: