美文网首页Sharding-JDBC
Sharding-JDBC-编排治理

Sharding-JDBC-编排治理

作者: 蓝胖子的白日梦丶 | 来源:发表于2019-04-29 18:10 被阅读89次

编排治理

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

不使用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>
</dependency>

<!--若使用etcd, 请下面Maven坐标-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-etcd</artifactId>
</dependency>

基于Java编码的规则配置

    // 省略配置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);

    // 获取数据源对象
    DataSource dataSource = OrchestrationShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig, new ConcurrentHashMap(), new Properties(), orchConfig);

基于Yaml的规则配置

或通过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坐标-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用etcd, 请加入下面Maven坐标-->
<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坐标-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

<!--若使用etcd, 请加入下面Maven坐标-->
<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>sharding-orchestration-reg-etcd</artifactId>
    <version>${sharding-sphere.version}</version>
</dependency>

基于Spring boot的规则配置

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

<?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>

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

相关文章

  • Sharding-JDBC-编排治理

    编排治理 使用治理功能需要指定一个注册中心。配置将全部存入注册中心,可以在每次启动时使用本地配置覆盖注册中心配置,...

  • ShardingJdbc 2.0 编排治理源码浅析

    先解释下什么编排治理:1.配置集中化与动态化,可支持数据源、表与分片策略的动态切换(2.0.0.M1)2.客户端的...

  • 杜甫经典诗词

    诗圣杜甫是唐代最伟大的现实主义诗人之一,他心系苍生,有“致君尧舜”的政治理想。但他仕途不顺,先是因李林甫编排了一场...

  • Sharding-JDBC-数据脱敏

    数据脱敏 该章节主要介绍如何使用数据脱敏功能,如何进行相关配置。数据脱敏功能即可与数据分片功能共同使用,又可作为单...

  • Sharding-JDBC-数据分片

    数据分片 不使用Spring 引入Maven依赖 基于Java编码的规则配置 Sharding-JDBC的分库分表...

  • Sharding-JDBC-强制路由

    强制路由 简介 ShardingSphere使用ThreadLocal管理分片键值进行Hint强制路由。可以通过编...

  • Sharding-JDBC-配置手册

    概述 配置是整个Sharding-JDBC的核心,是Sharding-JDBC中唯一与应用开发者打交道的模块。配置...

  • Sharding-JDBC-读写分离

    不使用Spring 引入Maven依赖 基于Java编码的规则配置 基于Yaml的规则配置 或通过Yaml方式配置...

  • 无标题文章

    1.领域划分,单体应用拆解; 2.服务契约定义 3.服务治理与配置中心 4.服务部署与编排 5.云化 6.持续集成...

  • 编排

    昨天,在k7054小绿皮车上,发生一件事。两个小丫头片子坐那儿玩手机,附近一老头也坐那儿玩手机。也可能是看着看着老...

网友评论

    本文标题:Sharding-JDBC-编排治理

    本文链接:https://www.haomeiwen.com/subject/sjsunqtx.html