我遇到了一个“nohttpresponseexception”异常,看起来好像我从连接池中选择了一个服务器单方面关闭的链接,之后我又重复了一遍,但还是会返回这个异常,我觉得如果我在重试时能够从连接池中选择一个新的连接,可以解决这个问题,所以我想知道如何在jestclient连接池中重试时选择一个新链接。
@Data
@Configuration
public class JestClientConfig {
private String url;
private Boolean multiThreaded;
private Integer maxTotalConnectionPerRoute;
private Integer maxTotalConnection;
private Integer connTimeout;
private Integer readTimeout;
private Integer connectionIdleTime;
@Bean
public JestClient getJestClient() {
String[] uriArr = url.split(",");
Set<String> serverUris = new LinkedHashSet<String>(Arrays.asList(uriArr));
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig.Builder(serverUris)
.multiThreaded(multiThreaded)
.defaultMaxTotalConnectionPerRoute(maxTotalConnectionPerRoute)
.maxTotalConnection(maxTotalConnection)
.maxConnectionIdleTime(connectionIdleTime, TimeUnit.MILLISECONDS)
.connTimeout(connTimeout)
.readTimeout(readTimeout)
.gson(new GsonBuilder().setDateFormat(DateUtil.TimeFormat.NORMAL_PATTERN.getValue()).create())
.build());
return factory.getObject();
}
}
use client:
@Resource
@Qualifier(value = "getJestClient")
private JestClient jestClient;
@Autowired
private JestClientConfig jestClientConfig;
retry:
public <T extends JestResult> T execute(Action<T> clientRequest, int retryTimes) {
if (retryTimes <= 0) {
return null;
}
try {
return ngccJestClient.execute(clientRequest);
} catch (Exception e) {
LOGGER.warn("ElasticsearchService.execute(): execution met an error, retryTimes = {}", retryTimes, e);
return execute(clientRequest, --retryTimes);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!