标签:主键 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); }
标签:主键 serve div dex hash timeout 模式 sele 服务
原文地址:http://www.cnblogs.com/Lxiaojiang/p/7565098.html