码迷,mamicode.com
首页 > 其他好文 > 详细

solr分布式索引【实战二、获取选中的solr服务客户端】

时间:2017-09-20 21:56:44      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:主键   serve   div   dex   hash   timeout   模式   sele   服务   

1.根据配置号获取当前选中的服务端:

 private static Map<String, SolrClient> selectServerMap = new ConcurrentHashMap<String, SolrClient>();
public static SolrClient getSelectServer(String configIndex) { if (configIndex == null) { configIndex = ConfigUtil.getProp("defaultConfigName"); } //确定solr是分布式模式 String solrMode = ConfigUtil.getProp("solr_mode_" + configIndex); //获取solr内核名称
String coreName
= ConfigUtil.getProp("coreName_" + configIndex); if (selectServerMap.get(configIndex) == null) {
//如果是单机版solr
if (solrMode.equals("single")) {
// http://192.168.1.100:8080/solr+"collection" HttpSolrClient sserver
= new HttpSolrClient.Builder(ConfigUtil.getProp("solr_url_" + configIndex) + "/" + coreName).build(); sserver.setConnectionTimeout(100000); selectServerMap.put(configIndex, sserver); } else { String zkHost = ConfigUtil.getProp("zkHost_" + configIndex); int zkClientTimeout = Integer.valueOf(ConfigUtil .getProp("zkClientTimeout_" + configIndex,DEFAULT_ZKTIMEOUT)); int zkConnectTimeout = Integer.valueOf(ConfigUtil .getProp("zkConnectTimeout_" + configIndex,DEFAULT_ZKTIMEOUT));
//主键字段 String idField
= ConfigUtil.getProp("idField_" + configIndex,DEFAULT_UNIQUEKEY_FIELD); ModifiableSolrParams params = new ModifiableSolrParams(); params.set(HttpClientUtil.PROP_CONNECTION_TIMEOUT, 30000); params.set(HttpClientUtil.PROP_SO_TIMEOUT, 30000); HttpClient client = HttpClientUtil.createClient(params); //CloudSolrClient sserver = new CloudSolrClient.Builder().withZkHost(zkHost).withHttpClient(client).build(); CloudSolrClient sserver = new Cetc4bCloudSolrClient(zkHost,client,configIndex); sserver.setDefaultCollection(coreName); sserver.setZkClientTimeout(zkClientTimeout); sserver.setZkConnectTimeout(zkConnectTimeout); sserver.setIdField(idField); selectServerMap.put(configIndex, sserver); } } return selectServerMap.get(configIndex); }

 

solr分布式索引【实战二、获取选中的solr服务客户端】

标签:主键   serve   div   dex   hash   timeout   模式   sele   服务   

原文地址:http://www.cnblogs.com/Lxiaojiang/p/7565098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!