Sharding-JDBC-編排治理

編排治理

使用治理功能需要指定一個注冊中心哩牍。配置將全部存入注冊中心,可以在每次啟動時使用本地配置覆蓋注冊中心配置疗垛,也可以只通過注冊中心讀取配置罢洲。

不使用Spring

引入Maven依賴

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-orchestration</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用zookeeper, 請加入下面Maven坐標(biāo)-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
</dependency>

<!--若使用etcd, 請下面Maven坐標(biāo)-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-etcd</artifactId>
</dependency>

基于Java編碼的規(guī)則配置

    // 省略配置dataSourceMap以及shardingRuleConfig
    // ...

    // 配置注冊中心
    RegistryCenterConfiguration regConfig = new RegistryCenterConfiguration();
    regConfig.setServerLists("localhost:2181");
    regConfig.setNamespace("sharding-sphere-orchestration");

    // 配置治理
    OrchestrationConfiguration orchConfig = new OrchestrationConfiguration("orchestration-sharding-data-source", regConfig, false);

    // 獲取數(shù)據(jù)源對象
    DataSource dataSource = OrchestrationShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig, new ConcurrentHashMap(), new Properties(), orchConfig);

基于Yaml的規(guī)則配置

或通過Yaml方式配置,與以上配置等價:

orchestration:
  name: orchestration-sharding-data-source
  overwrite: false
  registry:
    serverLists: localhost:2181
    namespace: sharding-sphere-orchestration
    DataSource dataSource = YamlOrchestrationShardingDataSourceFactory.createDataSource(yamlFile);

使用Spring

引入Maven依賴

<!-- for spring boot -->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-orchestration-spring-boot-starter</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用zookeeper, 請加入下面Maven坐標(biāo)-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用etcd, 請加入下面Maven坐標(biāo)-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-etcd</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>
<!-- for spring namespace -->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-jdbc-orchestration-spring-namespace</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用zookeeper, 請加入下面Maven坐標(biāo)-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用etcd, 請加入下面Maven坐標(biāo)-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-etcd</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

基于Spring boot的規(guī)則配置

spring.shardingsphere.orchestration.name=orchestration-sharding-data-source
spring.shardingsphere.orchestration.overwrite=false
spring.shardingsphere.orchestration.registry.server-lists=localhost:2181
spring.shardingsphere.orchestration.registry.namespace=sharding-jdbc-orchestration

基于Spring命名空間的規(guī)則配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:orchestraion="http://shardingsphere.apache.org/schema/shardingsphere/orchestration"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://shardingsphere.apache.org/schema/shardingsphere/orchestration
                           http://shardingsphere.apache.org/schema/shardingsphere/orchestration/orchestration.xsd">
     <import resource="namespace/shardingDataSourceNamespace.xml" />
     <orchestraion:registry-center id="regCenter" server-lists="localhost:3181" namespace="orchestration-spring-namespace-test" operation-timeout-milliseconds="1000" max-retries="3" />
     <orchestraion:sharding-data-source id="simpleShardingOrchestration" data-source-ref="simpleShardingDataSource" registry-center-ref="regCenter" />
</beans>

更多的詳細配置請參考配置手冊塑崖。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末七冲,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子规婆,更是在濱河造成了極大的恐慌澜躺,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,122評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件抒蚜,死亡現(xiàn)場離奇詭異掘鄙,居然都是意外死亡,警方通過查閱死者的電腦和手機嗡髓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評論 3 395
  • 文/潘曉璐 我一進店門操漠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人饿这,你說我怎么就攤上這事浊伙。” “怎么了长捧?”我有些...
    開封第一講書人閱讀 164,491評論 0 354
  • 文/不壞的土叔 我叫張陵嚣鄙,是天一觀的道長。 經(jīng)常有香客問我串结,道長哑子,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,636評論 1 293
  • 正文 為了忘掉前任肌割,我火速辦了婚禮赵抢,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘声功。我一直安慰自己烦却,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,676評論 6 392
  • 文/花漫 我一把揭開白布先巴。 她就那樣靜靜地躺著其爵,像睡著了一般。 火紅的嫁衣襯著肌膚如雪伸蚯。 梳的紋絲不亂的頭發(fā)上摩渺,一...
    開封第一講書人閱讀 51,541評論 1 305
  • 那天,我揣著相機與錄音剂邮,去河邊找鬼摇幻。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的绰姻。 我是一名探鬼主播枉侧,決...
    沈念sama閱讀 40,292評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼狂芋!你這毒婦竟也來了榨馁?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,211評論 0 276
  • 序言:老撾萬榮一對情侶失蹤帜矾,失蹤者是張志新(化名)和其女友劉穎翼虫,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體屡萤,經(jīng)...
    沈念sama閱讀 45,655評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡珍剑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,846評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了死陆。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片招拙。...
    茶點故事閱讀 39,965評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖翔曲,靈堂內(nèi)的尸體忽然破棺而出迫像,到底是詐尸還是另有隱情,我是刑警寧澤瞳遍,帶...
    沈念sama閱讀 35,684評論 5 347
  • 正文 年R本政府宣布闻妓,位于F島的核電站,受9級特大地震影響掠械,放射性物質(zhì)發(fā)生泄漏由缆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,295評論 3 329
  • 文/蒙蒙 一猾蒂、第九天 我趴在偏房一處隱蔽的房頂上張望均唉。 院中可真熱鬧,春花似錦肚菠、人聲如沸舔箭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,894評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽层扶。三九已至,卻和暖如春烙荷,著一層夾襖步出監(jiān)牢的瞬間镜会,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,012評論 1 269
  • 我被黑心中介騙來泰國打工终抽, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留戳表,地道東北人桶至。 一個月前我還...
    沈念sama閱讀 48,126評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像匾旭,于是被迫代替她去往敵國和親镣屹。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,914評論 2 355

推薦閱讀更多精彩內(nèi)容