增加ES配置管理,解决60,000 milliseconds timeout on connection http-outg问题
正在显示
1 个修改的文件
包含
8 行增加
和
0 行删除
@@ -10,6 +10,7 @@ import org.apache.http.auth.AuthScope; | @@ -10,6 +10,7 @@ import org.apache.http.auth.AuthScope; | ||
10 | import org.apache.http.auth.UsernamePasswordCredentials; | 10 | import org.apache.http.auth.UsernamePasswordCredentials; |
11 | import org.apache.http.client.CredentialsProvider; | 11 | import org.apache.http.client.CredentialsProvider; |
12 | import org.apache.http.impl.client.BasicCredentialsProvider; | 12 | import org.apache.http.impl.client.BasicCredentialsProvider; |
13 | +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; | ||
13 | import org.elasticsearch.client.RestClient; | 14 | import org.elasticsearch.client.RestClient; |
14 | import org.elasticsearch.client.RestClientBuilder; | 15 | import org.elasticsearch.client.RestClientBuilder; |
15 | import org.elasticsearch.client.RestHighLevelClient; | 16 | import org.elasticsearch.client.RestHighLevelClient; |
@@ -21,6 +22,7 @@ import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfig | @@ -21,6 +22,7 @@ import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfig | ||
21 | import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; | 22 | import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; |
22 | 23 | ||
23 | import javax.annotation.Resource; | 24 | import javax.annotation.Resource; |
25 | +import java.time.Duration; | ||
24 | import java.util.List; | 26 | import java.util.List; |
25 | 27 | ||
26 | /** | 28 | /** |
@@ -86,6 +88,12 @@ public class ElasticSearchConfig extends AbstractElasticsearchConfiguration { | @@ -86,6 +88,12 @@ public class ElasticSearchConfig extends AbstractElasticsearchConfiguration { | ||
86 | httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider); | 88 | httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider); |
87 | return httpAsyncClientBuilder; | 89 | return httpAsyncClientBuilder; |
88 | }); | 90 | }); |
91 | + builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() { | ||
92 | + @Override | ||
93 | + public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) { | ||
94 | + return httpAsyncClientBuilder.setKeepAliveStrategy(((httpResponse, httpContext) -> Duration.ofMinutes(5).toMillis())); | ||
95 | + } | ||
96 | + }); | ||
89 | RestHighLevelClient client = new RestHighLevelClient(builder); | 97 | RestHighLevelClient client = new RestHighLevelClient(builder); |
90 | return client; | 98 | return client; |
91 | } | 99 | } |
-
请 注册 或 登录 后发表评论