suxiaoyang 6 роки тому
батько
коміт
1164851911

+ 9 - 3
elasticsearch-starter/src/main/java/com/yihu/elasticsearch/config/ElasticSearchConfig.java

@ -14,11 +14,17 @@ import javax.annotation.PostConstruct;
@Configuration
public class ElasticSearchConfig {
    // 集群名称
    /**
     * 集群名称
     */
    private String clusterName;
    // 节点
    /**
     * 节点
     */
    private String clusterNodes;
    // 是否开启嗅探
    /**
     * 是否开启嗅探
     */
    private boolean clientTransportSniff;
    public String getClusterName() {

+ 2 - 3
elasticsearch-transport-starter/src/main/java/com/yihu/elasticsearch/ElasticSearchPool.java

@ -16,8 +16,7 @@ import java.net.InetSocketAddress;
import java.util.Properties;
/**
 * @author progr1mmer
 * @date Created on 2018/1/4.
 * Created by progr1mmer on 2018/1/4.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@ -31,7 +30,7 @@ public class ElasticSearchPool {
    private TransportClient getTransportClient() {
        Settings settings = Settings.builder()
                .put("cluster.name", elasticSearchConfig.getClusterName())
                .put("client.transport.sniff", false)
                .put("client.transport.sniff", elasticSearchConfig.isClientTransportSniff())
                .build();
        String[] nodeArr = elasticSearchConfig.getClusterNodes().split(",");
        InetSocketTransportAddress[] socketArr = new InetSocketTransportAddress[nodeArr.length];

+ 20 - 2
elasticsearch-transport-starter/src/main/java/com/yihu/elasticsearch/config/ElasticSearchConfig.java

@ -6,6 +6,7 @@ import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
/**
 * Config - ES TransportClient 配置
 * @author progr1mmer
 * @date Created on 2018/1/4.
 */
@ -13,10 +14,18 @@ import javax.annotation.PostConstruct;
@Configuration
public class ElasticSearchConfig {
    // 集群名称
    /**
     * 集群名称
     */
    private String clusterName;
    // 节点
    /**
     * 节点
     */
    private String clusterNodes;
    /**
     * 是否开启嗅探
     */
    private boolean clientTransportSniff;
    public String getClusterName() {
        return clusterName;
@ -34,11 +43,20 @@ public class ElasticSearchConfig {
        this.clusterNodes = clusterNodes;
    }
    public boolean isClientTransportSniff() {
        return clientTransportSniff;
    }
    public void setClientTransportSniff(boolean clientTransportSniff) {
        this.clientTransportSniff = clientTransportSniff;
    }
    @PostConstruct
    private void configInfo() {
        StringBuilder info = new StringBuilder("{");
        info.append("\n  elasticsearch.cluster-name = " + clusterName);
        info.append("\n  elasticsearch.cluster-nodes = " + clusterNodes);
        info.append("\n  elasticsearch.client-transport-sniff = " + clientTransportSniff);
        info.append("\n}");
        System.out.println("Elasticsearch.configInfo : " + info.toString());
    }