|
@@ -3,6 +3,7 @@ package com.persagy.apm.common.configuration;
|
|
|
import org.apache.http.HttpHost;
|
|
|
import org.elasticsearch.client.RestClient;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
@@ -13,12 +14,31 @@ import org.springframework.context.annotation.Configuration;
|
|
|
*/
|
|
|
@Configuration
|
|
|
public class ElasticSearchConfig {
|
|
|
- @Bean
|
|
|
+
|
|
|
+ @Value("${elasticsearch.host}")
|
|
|
+ private String host;
|
|
|
+
|
|
|
+ @Value("${elasticsearch.port}")
|
|
|
+ private int port;
|
|
|
+
|
|
|
+ @Value("${elasticsearch.connectTimeout:15000}")
|
|
|
+ private int connectTimeout;
|
|
|
+
|
|
|
+ @Value("${elasticsearch.socketTimeout:15000}")
|
|
|
+ private int socketTimeout;
|
|
|
+
|
|
|
+ @Value("${elasticsearch.connectionRequestTimeout:15000}")
|
|
|
+ private int connectionRequestTimeout;
|
|
|
+
|
|
|
+ @Bean(destroyMethod = "close",name = "client")
|
|
|
public RestHighLevelClient restHighLevelClient() {
|
|
|
return new RestHighLevelClient(
|
|
|
RestClient.builder(
|
|
|
- new HttpHost("172.16.1.186", 9200, "http")
|
|
|
- )
|
|
|
+ new HttpHost(host, port, "http")
|
|
|
+ ).setRequestConfigCallback(requestConfigBuilder->requestConfigBuilder
|
|
|
+ .setConnectTimeout(connectTimeout)
|
|
|
+ .setSocketTimeout(socketTimeout)
|
|
|
+ .setConnectionRequestTimeout(connectionRequestTimeout))
|
|
|
);
|
|
|
}
|
|
|
}
|