我正在使用JEST在Spring Boot应用程序中连接elasticsearch。当应用程序空闲(不向elasticsearch发送任何请求)一段时间后,JestClient会抛出SocketTImeoutException。我使用bean创建客户端:
@Bean
public JestClient client() throws Exception {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder(esURL)
.multiThreaded(true)
.connTimeout(60000)
.readTimeout(60000)
.defaultMaxTotalConnectionPerRoute(10)
.maxTotalConnection(100).build());
return factory.getObject();
}
这里有什么我忽略的吗?
maxConnectionIdleTime
,以便在实际使用之前杀死空闲连接(这将导致您收到超时异常)。测试本身中的示例:https://github.com/searchbox-io/Jest/blob/v2.0.4/jest/src/test/java/io/searchbox/client/JestClientFactoryIntegrationTest.java#L116 - Andrei Stefan