当前位置:网站首页>Configuration and practice of shardingsphere JDBC sub database separation of read and write

Configuration and practice of shardingsphere JDBC sub database separation of read and write

2022-06-13 03:25:00 Python's path to becoming a God

shardingsphere-jdbc Configuration and practice of sub database - Read / write separation

Main library :ds0, Slave Library :s0, Main library :ds1, Slave Library :s1

To configure

spring:
  shardingsphere:
    #  Data source configuration 
    datasource:
      names: ds0,s0,ds1,s1
      #  Slice library configuration 
      ds0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/ds0?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        username: root
        password: 123456
        initial-size: 5
        maxActive: 5
        maxWait: 60000
        poolPreparedStatements: true
      s0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/s0?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        username: root
        password: 123456
        initial-size: 5
        maxActive: 5
        maxWait: 60000
        poolPreparedStatements: true
      ds1:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/ds1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        username: root
        password: 123456
        initial-size: 5
        maxActive: 5
        maxWait: 60000
        poolPreparedStatements: true
      s1:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/s1?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
        username: root
        password: 123456
        initial-size: 5
        maxActive: 5
        maxWait: 60000
        poolPreparedStatements: true
    sharding:
      default-database-strategy:
        standard:
          sharding-column: id
          precise-algorithm-class-name: com.clsu.algorithm.MyPreciseAlgorithm
          range-algorithm-class-name: com.clsu.algorithm.MyRangeAlgorithm
      tables:
        test:
          actual-data-nodes: ds$->{0..1}.test$->{0..1}
          table-strategy:
            standard:
              sharding-column: id
              range-algorithm-class-name: com.clsu.algorithm.MyRangeAlgorithm
              #split database impl
              precise-algorithm-class-name: com.clsu.algorithm.MyPreciseAlgorithm
          key-generator:
            column: id
            type: SNOWFLAKE
      #  Read write separation configuration 
      master-slave-rules:
        ds0:
          master-data-source-name: ds0
          slave-data-source-names: s0
        ds1:
          master-data-source-name: ds1
          slave-data-source-names: s1
    props:
      sql:
        show: true

原网站

版权声明
本文为[Python's path to becoming a God]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280530515864.html