blog

ShardingSphere 4.x オーケストレーション・ガバナンスのためのSharding-JDBCユーザーマニュアル

ガバナンス機能を使うには、設定センターとレジストリを指定する必要があります。コンフィギュレーションはすべてコンフィギュレーションセンターに保存され、起動ごとにローカルコンフィギュレーションを使ってコン...

Jul 10, 2020 · 4 min. read
シェア

ガバナンス機能を使用するには、設定センターとレジストリを指定する必要があります。設定はすべてコンフィギュレーションセンターに保存され、起動ごとにローカル設定を使って上書きしたり、コンフィギュレーションセンターを通してのみ設定を読み込んだりすることができます。

Springを使わない場合

Maven依存関係の導入

<dependency>
 <groupId>org.apache.shardingsphere</groupId>
 <artifactId>sharding-jdbc-orchestration</artifactId>
 <version>${sharding-sphere.version}</version>
</dependency>
<!--zookeeperを使用している場合、以下のMaven座標を追加する--。>
<dependency>
 <groupId>org.apache.shardingsphere</groupId>
 <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
 <version>${sharding-sphere.version}</version>
</dependency>

Javaコーディングに基づくルール設定

 // dataSourceMapとshardingRuleConfigの設定を省略する。
 // ...
 // レジストリを設定する
 Properties properties = new Properties();
 properties.setProperty("overwrite", overwrite);
 CenterConfiguration centerConfiguration = new CenterConfiguration("zookeeper", properties);
 centerConfiguration.setServerLists("localhost:2181");
 centerConfiguration.setNamespace("sharding-sphere-orchestration");
 centerConfiguration.setOrchestrationType("registry_center,config_center");
 // コンフィギュレーションガバナンス
 Map<String, CenterConfiguration> instanceConfigurationMap = new HashMap<String, CenterConfiguration>();
 instanceConfigurationMap.put("orchestration-sharding-data-source", centerConfiguration);
 // データソースオブジェクトを取得する
 OrchestrationShardingDataSourceFactory.createDataSource(
 createDataSourceMap(), createShardingRuleConfig(), new HashMap<String, Object>(), new Properties(), new OrchestrationConfiguration(instanceConfigurationMap));

Yamlベースのルール設定

または、Yaml経由で設定してください:

orchestration:
 orchestration_ds:
 orchestrationType: registry_center,config_center
 instanceType: zookeeper
 serverLists: localhost:2181
 namespace: orchestration
 props:
 overwrite: true
 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座標を追加する--。>
<dependency>
 <groupId>org.apache.shardingsphere</groupId>
 <artifactId>sharding-orchestration-reg-zookeeper-curator</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座標を追加する--。>
<dependency>
 <groupId>org.apache.shardingsphere</groupId>
 <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
 <version>${sharding-sphere.version}</version>
</dependency>

Spring bootに基づくルール構成

spring.shardingsphere.orchestration.spring_boot_ds_sharding.orchestration-type=registry_center,config_center
spring.shardingsphere.orchestration.spring_boot_ds_sharding.instance-type=zookeeper
spring.shardingsphere.orchestration.spring_boot_ds_sharding.server-lists=localhost:2181
spring.shardingsphere.orchestration.spring_boot_ds_sharding.namespace=orchestration-spring-boot-sharding-test
spring.shardingsphere.orchestration.spring_boot_ds_sharding.props.overwrite=true

Springの名前空間に基づくルール構成

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://..org/2100"/XMLSchema-instance"
 xmlns:orchestraion="http://..org/schema/shardingsphere/orchestration"
 xmlns="http://..org/schema/beans"
 xsi:schemaLocation="http://..org/schema/beans
 http://..org/schema/beans/spring-.xsd
 http://..org/schema/shardingsphere/orchestration
 http://..org/schema/shardingsphere/orchestration/.xsd">
 <import resource="namespace/shardingDataSourceNamespace.xml" />
 <util:properties id="instance-props">
 <prop key="max-retries">3</prop>
 <prop key="operation-timeout-milliseconds">3000</prop>
 </util:properties>
 <orchestraion:instance id="regCenter" orchestration-type="registry_center,config_center" instance-type="zookeeper" server-lists="localhost:2181" namespace="orchestration-spring-namespace-demo"
 props-ref="instance-props" />
 <orchestraion:sharding-data-source id="shardingDatabasesTablesDataSource" data-source-ref="realShardingDatabasesTablesDataSource" instance-ref="regCenter" overwrite="true" />
 <orchestraion:master-slave-data-source id="masterSlaveDataSource" data-source-ref="realMasterSlaveDataSource" instance-ref="regCenter" overwrite="true" />
 <orchestraion:encrypt-data-source id="encryptDataSource" data-source-ref="realEncryptDataSource" instance-ref="regCenter" overwrite="true" />
</beans>
Read next

あなたは本当にフロントエンド開発を理解している?

フロントエンド開発は、Webフロントエンド開発の略であり、インターネット上で様々な説明や説明がたくさんありますが、今日は私自身の視点と理解からフロントエンド開発について話します。3つの要素 Webフロントエンド開発技術には、HTML、CSS、そしてRIAの3つの要素があります。

Jul 10, 2020 · 3 min read