apache 的HttpClient 的默认重试机制
maven
异常重试log
RetryExec
org/apache/http/impl/execchain/RetryExec.java
DefaultHttpRequestRetryHandler
org/apache/http/impl/client/DefaultHttpRequestRetryHandler.java
<dependency>
<groupId>org.apache.httpcomponents </groupId>
<artifactId>httpclient </artifactId>
<version>4.5.2</version>
下载apache</dependency>
2017-01-31 19:31:39.057 INFO 3873 --- [askScheduler-13] o.apache.hain.RetryExec : I/O exception (org.apache.http.NoHttpRespon seException) caught when processing request to {}->192.168.99.100:8080: The target server failed to respond
2017-01-31 19:31:39.058 INFO 3873 --- [askScheduler-13] o.apache.hain.RetryExec : Retrying request to {}->192.168.99.100:8
080
/**
* Request executor in the request execution chain that is responsible
* for making a decision whether a request failed due to an I/O error
* should be re-executed.
* <p>
* Further responsibilities such as communication with the opposite
* endpoint is delegated to the next executor in the request execution
* chain.
* </p>
*
* @since 4.3
*/
@Immutable
public class RetryExec implements ClientExecChain {
private final Log log = Log(getClass());
private final ClientExecChain requestExecutor;
private final HttpRequestRetryHandler retryHandler;
public RetryExec(
final ClientExecChain requestExecutor,
final HttpRequestRetryHandler retryHandler) {
默认重试3次,三次都失败则抛出NoHttpResponseException或其他异常
doc /**
* The default {@link HttpRequestRetryHandler} used by request executors.
*
* @since 4.0
*/
@Immutable
public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler { public static final DefaultHttpRequestRetryHandler INSTANCE = new DefaultHttpRequestRetryHandler(); /** the number of times a method will be retried */
private final int retryCount;
/** Whether or not methods that have successfully sent their request will be retried */ private final boolean requestSentRetryEnabled;
private final Set<Class<? extends IOException>> nonRetriableClasses;
/**
* Create the request retry handler using the specified IOException classes
*
* @param retryCount how many times to retry; 0 means no retries
* @param requestSentRetryEnabled true if it's OK to retry requests that have been sent
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论