频道栏目
首页 > 网络 > 云计算 > 正文

世界杯投注官网

2018-07-11 11:31:37      个评论    来源:LEON的博客  
收藏   我要投稿
package com.ctpsp.custominfo.api.configuration;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.net.UnknownHostException;
@Configuration
public class ElasticSearchConfiguration {
    @Value("${elastic.esServerIps}")
    private String esServerIps;
    @Value("${elastic.port}")
    private int port;
    private static TransportClient  transPort = null;
    @Bean
    public TransportClient client() throws UnknownHostException {
        try {
            Settings settings = Settings.builder()
                    .put("cluster.name", "leon")
                    .build();
            transPort = new PreBuiltTransportClient(settings);
            String esIps[] = esServerIps.split(",");
            for (String esIp : esIps) {//添加集群IP列表
                TransportAddress transportAddress =  new InetSocketTransportAddress(
                        InetAddresses.forString(esIp),
                        9300);
                transPort.addTransportAddresses(transportAddress);
            }
            return transPort;
        }catch (Exception e){
            e.printStackTrace();
            if (transPort != null){
                transPort.close();
            }
        }
        return null;
    }
}

properties

elastic.esServerIps=192.168.1.21,192.168.1.21
elastic.port= 9300
上一篇:行存储VS列存储
下一篇:线程简介
相关文章
图文推荐

关于我们 | 联系我们 | 服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑--致力于做实用的IT技术学习网站