RetryPolicy Class
- java.
lang. Object - com.
azure. core. http. policy. RetryPolicy
- com.
Implements
public class RetryPolicy
implements HttpPipelinePolicy
The RetryPolicy
class is an implementation of the HttpPipelinePolicy interface. This policy handles HTTP retries by determining if an HTTP request should be retried based on the received HttpResponse.
This class is useful when you need to handle HTTP retries in a pipeline. It uses a RetryStrategy to decide if a request should be retried. By default, it uses the ExponentialBackoff strategy, which uses a delay duration that exponentially increases with each retry attempt until an upper bound is reached.
Code sample:
In this example, a RetryPolicy
is created which can then be added to the pipeline. For the request then sent by the pipeline, if the server responds with a status code that indicates a transient error, the request will be retried according to the RetryStrategy used by the RetryPolicy
.
RetryPolicy retryPolicy = new RetryPolicy();
Constructor Summary
Constructor | Description |
---|---|
RetryPolicy() |
Creates RetryPolicy using ExponentialBackoff() as the RetryStrategy. |
RetryPolicy(RetryOptions retryOptions) |
Creates a RetryPolicy with the provided RetryOptions. |
RetryPolicy(RetryStrategy retryStrategy) |
Creates a RetryPolicy with the provided RetryStrategy. |
RetryPolicy(RetryStrategy retryStrategy, String retryAfterHeader, ChronoUnit retryAfterTimeUnit) |
Creates RetryPolicy with the provided RetryStrategy and default ExponentialBackoff as RetryStrategy. |
RetryPolicy(String retryAfterHeader, ChronoUnit retryAfterTimeUnit) |
Creates RetryPolicy using ExponentialBackoff() as the RetryStrategy and uses |
Method Summary
Modifier and Type | Method and Description |
---|---|
Mono<Http |
process(HttpPipelineCallContext context, HttpPipelineNextPolicy next)
Processes provided request context and invokes the next policy. |
Http |
processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next)
Processes provided request context and invokes the next policy synchronously. |
Methods inherited from java.lang.Object
Constructor Details
RetryPolicy
public RetryPolicy()
Creates RetryPolicy using ExponentialBackoff() as the RetryStrategy.
RetryPolicy
public RetryPolicy(RetryOptions retryOptions)
Creates a RetryPolicy with the provided RetryOptions.
Parameters:
RetryPolicy
public RetryPolicy(RetryStrategy retryStrategy)
Creates a RetryPolicy with the provided RetryStrategy.
Parameters:
RetryPolicy
public RetryPolicy(RetryStrategy retryStrategy, String retryAfterHeader, ChronoUnit retryAfterTimeUnit)
Creates RetryPolicy with the provided RetryStrategy and default ExponentialBackoff as RetryStrategy. It will use provided retryAfterHeader
in HttpResponse headers for calculating retry delay.
Parameters:
retryAfterHeader
is null.
RetryPolicy
public RetryPolicy(String retryAfterHeader, ChronoUnit retryAfterTimeUnit)
Creates RetryPolicy using ExponentialBackoff() as the RetryStrategy and uses retryAfterHeader
to look up the wait period in the returned HttpResponse to calculate the retry delay when a recoverable HTTP error is returned.
Parameters:
Retry-After
or x-ms-retry-after-ms
, to lookup
for the retry delay. If the value is null, calculateRetryDelay(int retryAttempts) will compute the delay
and ignore the delay provided in response header.
retryAfterHeader
is null.
Method Details
process
public Mono
Processes provided request context and invokes the next policy.
Parameters:
processSync
public HttpResponse processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next)
Processes provided request context and invokes the next policy synchronously.
Parameters:
Applies to
Azure SDK for Java