ShardingSphere 4.x Sharding-JDBC 用户手册之编排治理使用手册

使用治理功能需要指定配置中心和注册中心。配置将全部存入配置中心,可以在每次启动时使用本地配置覆盖配置中心配置,也可以只通过配置中心读取配置。

不使用Spring

引入Maven依赖


    org.apache.shardingsphere
    sharding-jdbc-orchestration
    ${sharding-sphere.version}




    org.apache.shardingsphere
    sharding-orchestration-reg-zookeeper-curator
    ${sharding-sphere.version}

基于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 instanceConfigurationMap = new HashMap();
    instanceConfigurationMap.put("orchestration-sharding-data-source", centerConfiguration);

    // 获取数据源对象
    OrchestrationShardingDataSourceFactory.createDataSource(
                        createDataSourceMap(), createShardingRuleConfig(), new HashMap(), 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依赖



    org.apache.shardingsphere
    sharding-jdbc-orchestration-spring-boot-starter
    ${sharding-sphere.version}




    org.apache.shardingsphere
    sharding-orchestration-reg-zookeeper-curator
    ${sharding-sphere.version}


    org.apache.shardingsphere
    sharding-jdbc-orchestration-spring-namespace
    ${sharding-sphere.version}




    org.apache.shardingsphere
    sharding-orchestration-reg-zookeeper-curator
    ${sharding-sphere.version}

基于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命名空间的规则配置



     
     
               3
               3000
         
         
         
         
         

更多的详细配置请参考配置手册

你可能感兴趣的:(数据库)