solr分布式索引【實戰一、分區配置讀取:工具類configUtil.java,讀取配置程式碼片段,配置執行個體】

來源:互聯網
上載者:User

標籤:print   http   mode   pat   pre   publish   ade   tac   host   

 1     private static Properties prop = new Properties(); 2  3     private static String confFilePath = "conf" + File.separator + "config.properties";// 設定檔目錄 4     static { 5         // 載入properties 6         InputStream is = null; 7         InputStreamReader isr = null; 8         try { 9             File f = new File(confFilePath);10             if (f.exists()) {11                 is = new BufferedInputStream(new FileInputStream(f));12                 isr = new InputStreamReader(is, "utf-8");13                 prop.load(isr);14                 is.close();15                 is = null;16                 isr.close();17                 isr = null;18             } else {19                 /** 修改為資源檔讀取方式,方便以後工程打包 */20                 is = ConfigUtil.class.getClassLoader().getResourceAsStream("config.properties");21                 if (is != null) {22                     isr = new InputStreamReader(is, "utf-8");23                     prop.load(isr);24                     is.close();25                     is = null;26                     isr.close();27                     isr = null;28                 } else {29                     System.err.println("嚴重警告:項目的設定檔“config.properties”缺失了,該檔案應在src目錄下或者工程目錄的conf檔案夾中,"30                             + "繼續運行將可能因資料庫等配置參數缺失而導致重大異常!");31 32                     // System.exit(-1);33                 }34             }35         } catch (Exception e) {36             e.printStackTrace();37         } finally {38             if (is != null) {39                 try {40                     is.close();41                 } catch (IOException e) {42                     e.printStackTrace();43                 }44                 is = null;45             }46         }47 48     }

 

讀取配置程式碼片段:

/**擷取所有的分區的cloud配置序號 * @return */public static Set<String> getAllCloudSplitModeConfigIndex(){Set<String> result = new HashSet<String>();Properties props = ConfigUtil.getProperties();Set<Object> allKeys = props.keySet();
//遍曆設定檔,讀取所有索引值對。for(Object s:allKeys){String key = (String)s;if(key.startsWith("solr_mode_")){String value = StringUtil.trim(ConfigUtil.getProp(key)); //如果是分布式模式
if("cloud".equalsIgnoreCase(value)){String configName = key.replaceFirst("solr_mode_", ""); //如果是按照時間分區
if("true".equalsIgnoreCase(ConfigUtil.getProp("split_mode_" + configName))){result.add(configName);}}}}return result;}

  

設定檔執行個體:

######## solr ######
defaultConfigName = 1

#####solr1########
solr_url_1 = http://***********:8080/solr  (單機)
zkHost_1 = 192.168.*.*:2181,192.168.*.*:2181,192.168.*.*:2181(zookeeper地址)
solr_mode_1 = cloud (分布式模式)
coreName_1 = collection1 (核心名稱)
zkClientTimeout_1 = 200000
zkConnectTimeout_1 = 10000
connectionTimeout_1 = 100000
idField_1 = guidSolr (uniqueKey)
split_mode_1 = true (分區模式開啟)
splitTimeField_1 = publishTime (分區欄位)

#####solr2#######
solr_url_2 = http://192.168.*.*:8080/solr(單機)
zkHost_2 = 192.168.*.*:2181,192.168.*.*:2181,192.168.*.*:2181
solr_mode_2 = cloud
coreName_2 = collection2
zkClientTimeout_2 = 200000
zkConnectTimeout_2 = 10000
connectionTimeout_2 = 100000
idField_2 = guidSolr
split_mode_2 = false(分區模式關閉)

 

solr分布式索引【實戰一、分區配置讀取:工具類configUtil.java,讀取配置程式碼片段,配置執行個體】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.