ES Rest高级客户端空闲一段时间后抛出SocketTimeoutException [英] ES Rest High Level Client throws SocketTimeoutException after being idle for sometime
问题描述
RestHighLevelClient
用于在spring-boot应用程序中连接到ES 6.4(托管在AWS上).当应用程序空闲一段时间后,请求到达时, RestHighLevelClient
会抛出 SocketTimeoutException
:
RestHighLevelClient
is used to connect to ES 6.4(hosted on AWS) in a spring-boot app. When the app goes idle for some time, and request arrives, then the RestHighLevelClient
throws SocketTimeoutException
:
[Request processing failed; nested exception is org.springframework.data.elasticsearch.ElasticsearchException: Error while bulk for request: org.elasticsearch.action.bulk.BulkRequest@21511b6c] w
java.net.SocketTimeoutException: 5,000 milliseconds timeout on connection http-outgoing-38 [ACTIVE]
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.timeout(HttpAsyncRequestExecutor.java:387) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:92) ~[httpasyncclient-4.1.4.jar!/:4.1.4]
at org.apache.http.impl.nio.client.InternalIODispatch.onTimeout(InternalIODispatch.java:39) ~[httpasyncclient-4.1.4.jar!/:4.1.4]
at org.apache.http.impl.nio.reactor.AbstractIODispatch.timeout(AbstractIODispatch.java:175) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.reactor.BaseIOReactor.sessionTimedOut(BaseIOReactor.java:263) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.timeoutCheck(AbstractIOReactor.java:492) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.reactor.BaseIOReactor.validate(BaseIOReactor.java:213) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:280) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591) ~[httpcore-nio-4.4.11.jar!/:4.4.11]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
RestHighLevelClient使用以下方法创建:
RestHighLevelClient is created using:
@Bean
RestHighLevelClient client() {
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(elasticsearchHostAndPort)
.build();
return RestClients.create(clientConfiguration).rest();
}
使用
spring-data-elasticsearch
版本 3.2.0.M2
.
有任何提示/解决方法吗?
Any hints/workarounds?
推荐答案
在 RestClientBuilder.createHttpClient()
中,套接字超时和连接超时的默认值设置为30秒和10秒.
In RestClientBuilder.createHttpClient()
the defaults for socket timeout and connection timeout are set to 30 and 10 seconds.
您可以通过实现 RestClientBuilder.RequestConfigCallback
并在 RestHighLevelClient
我们做了类似的事情
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder builder) {
return builder.setSocketTimeout(socketTimeout); // try to prevent SocketTimeoutException
}
这篇关于ES Rest高级客户端空闲一段时间后抛出SocketTimeoutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!