Package com.azure.core.http.policy
Class RetryPolicy
java.lang.Object
com.azure.core.http.policy.RetryPolicy
- All Implemented Interfaces:
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();
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRetryPolicy(RetryOptions retryOptions) Creates aRetryPolicywith the providedRetryOptions.RetryPolicy(RetryStrategy retryStrategy) Creates aRetryPolicywith the providedRetryStrategy.RetryPolicy(RetryStrategy retryStrategy, String retryAfterHeader, ChronoUnit retryAfterTimeUnit) CreatesRetryPolicywith the providedRetryStrategyand defaultExponentialBackoffasRetryStrategy.RetryPolicy(String retryAfterHeader, ChronoUnit retryAfterTimeUnit) CreatesRetryPolicyusingExponentialBackoff()as theRetryStrategyand usesretryAfterHeaderto look up the wait period in the returnedHttpResponseto calculate the retry delay when a recoverable HTTP error is returned. -
Method Summary
Modifier and TypeMethodDescriptionprocess(HttpPipelineCallContext context, HttpPipelineNextPolicy next) Processes provided request context and invokes the next policy.processSync(HttpPipelineCallContext context, HttpPipelineNextSyncPolicy next) Processes provided request context and invokes the next policy synchronously.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.core.http.policy.HttpPipelinePolicy
getPipelinePosition
-
Constructor Details
-
RetryPolicy
public RetryPolicy() -
RetryPolicy
CreatesRetryPolicyusingExponentialBackoff()as theRetryStrategyand usesretryAfterHeaderto look up the wait period in the returnedHttpResponseto calculate the retry delay when a recoverable HTTP error is returned.- Parameters:
retryAfterHeader- The HTTP header, such asRetry-Afterorx-ms-retry-after-ms, to lookup for the retry delay. If the value is null,RetryStrategy.calculateRetryDelay(RequestRetryCondition)will compute the delay and ignore the delay provided in response header.retryAfterTimeUnit- The time unit to use when applying the retry delay. Null is valid if, and only if,retryAfterHeaderis null.- Throws:
NullPointerException- WhenretryAfterTimeUnitis null andretryAfterHeaderis not null.
-
RetryPolicy
public RetryPolicy(RetryStrategy retryStrategy, String retryAfterHeader, ChronoUnit retryAfterTimeUnit) CreatesRetryPolicywith the providedRetryStrategyand defaultExponentialBackoffasRetryStrategy. It will use providedretryAfterHeaderinHttpResponseheaders for calculating retry delay.- Parameters:
retryStrategy- TheRetryStrategyused for retries.retryAfterHeader- The HTTP header, such as 'Retry-After' or 'x-ms-retry-after-ms', to lookup for the retry delay. If the value is null,RetryPolicywill use the retry strategy to compute the delay and ignore the delay provided in response header.retryAfterTimeUnit- The time unit to use when applying the retry delay. null is valid if, and only if,retryAfterHeaderis null.- Throws:
NullPointerException- IfretryStrategyis null or whenretryAfterTimeUnitis null andretryAfterHeaderis not null.
-
RetryPolicy
Creates aRetryPolicywith the providedRetryStrategy.- Parameters:
retryStrategy- TheRetryStrategyused for retries.- Throws:
NullPointerException- IfretryStrategyis null.
-
RetryPolicy
Creates aRetryPolicywith the providedRetryOptions.- Parameters:
retryOptions- TheRetryOptionsused to configure thisRetryPolicy.- Throws:
NullPointerException- IfretryOptionsis null.
-
-
Method Details
-
process
Description copied from interface:HttpPipelinePolicyProcesses provided request context and invokes the next policy.- Specified by:
processin interfaceHttpPipelinePolicy- Parameters:
context- The request context.next- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-
processSync
Description copied from interface:HttpPipelinePolicyProcesses provided request context and invokes the next policy synchronously.- Specified by:
processSyncin interfaceHttpPipelinePolicy- Parameters:
context- The request context.next- The next policy to invoke.- Returns:
- A publisher that initiates the request upon subscription and emits a response on completion.
-