Parcourir la source

bug提交 ES集群连接修复

QGC il y a 4 ans
Parent
commit
42cf61aaf8

+ 4 - 0
common/fire-common/pom.xml

@@ -38,6 +38,10 @@
             <groupId>org.apache.tomcat.embed</groupId>
             <artifactId>tomcat-embed-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
     </dependencies>
 
     <artifactId>fire-common</artifactId>

+ 6 - 9
common/fire-common/src/main/java/com.fire.common/esdemo/config/EsConfig.java

@@ -1,40 +1,37 @@
 package com.fire.common.esdemo.config;
 
-import org.apache.http.HttpHost;
-import org.elasticsearch.client.RestClient;
-import org.elasticsearch.client.RestClientBuilder;
+import cn.hutool.core.util.StrUtil;
 import org.elasticsearch.client.RestHighLevelClient;
-import org.elasticsearch.index.fielddata.ScriptDocValues;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.elasticsearch.client.ClientConfiguration;
 import org.springframework.data.elasticsearch.client.RestClients;
-import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
 import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
 
 
+import java.net.InetSocketAddress;
 import java.time.Duration;
+import java.util.List;
 
 
 @Configuration
 public class EsConfig {
 
     @Value("${elasticsearch.rest.uris}")
-    private String hostAndPort;
+    private String hostAndPorts;
 
 
     @Bean
     public RestHighLevelClient elasticsearchClient() {
+        String[] hostAndPort = StrUtil.splitToArray(hostAndPorts, ';');
         ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                 .connectedTo(hostAndPort)
                 .withConnectTimeout(Duration.ofSeconds(5))
                 .withSocketTimeout(Duration.ofSeconds(3))
                 .build();
+
         return RestClients.create(clientConfiguration).rest();
-//        String[] res = hostAndPort.split(":");
-//        RestClientBuilder builder = RestClient.builder(new HttpHost(res[0],Integer.valueOf(res[1])));
-//        return new RestHighLevelClient(builder);
     }
 
     @Bean