Mixed Rules

Configuration Item Explanation

  1. # data source configuration
  2. spring.shardingsphere.datasource.names= write-ds0,write-ds1,write-ds0-read0,write-ds1-read0
  3. spring.shardingsphere.datasource.write-ds0.url= # Database URL connection
  4. spring.shardingsphere.datasource.write-ds0.type= # Database connection pool type name
  5. spring.shardingsphere.datasource.write-ds0.driver-class-name= # Database driver class name
  6. spring.shardingsphere.datasource.write-ds0.username= # Database username
  7. spring.shardingsphere.datasource.write-ds0.password= # Database password
  8. spring.shardingsphere.datasource.write-ds0.xxx= # Other properties of database connection pool
  9. spring.shardingsphere.datasource.write-ds1.url= # Database URL connection
  10. # ...Omit specific configuration.
  11. spring.shardingsphere.datasource.write-ds0-read0.url= # Database URL connection
  12. # ...Omit specific configuration.
  13. spring.shardingsphere.datasource.write-ds1-read0.url= # Database URL connection
  14. # ...Omit specific configuration.
  15. # Sharding rules configuration
  16. # Databases sharding strategy
  17. spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-column=user_id
  18. spring.shardingsphere.rules.sharding.default-database-strategy.standard.sharding-algorithm-name=default-database-strategy-inline
  19. # Binding table rules configuration ,and multiple groups of binding-tables configured with arrays
  20. spring.shardingsphere.rules.sharding.binding-tables[0]=t_user,t_user_detail
  21. spring.shardingsphere.rules.sharding.binding-tables[1]= # Binding table names,multiple table name are separated by commas
  22. spring.shardingsphere.rules.sharding.binding-tables[x]= # Binding table names,multiple table name are separated by commas
  23. # Broadcast table rules configuration
  24. spring.shardingsphere.rules.sharding.broadcast-tables= # Broadcast table names,multiple table name are separated by commas
  25. # Table sharding strategy
  26. # The enumeration value of `ds_$->{0..1}` is the name of the logical data source configured with readwrite-splitting
  27. spring.shardingsphere.rules.sharding.tables.t_user.actual-data-nodes=ds_$->{0..1}.t_user_$->{0..1}
  28. spring.shardingsphere.rules.sharding.tables.t_user.table-strategy.standard.sharding-column=user_id
  29. spring.shardingsphere.rules.sharding.tables.t_user.table-strategy.standard.sharding-algorithm-name=user-table-strategy-inline
  30. # Data encrypt configuration
  31. # Table `t_user` is the name of the logical table that uses for data sharding configuration.
  32. spring.shardingsphere.rules.encrypt.tables.t_user.columns.user_name.cipher-column=user_name
  33. spring.shardingsphere.rules.encrypt.tables.t_user.columns.user_name.encryptor-name=name-encryptor
  34. spring.shardingsphere.rules.encrypt.tables.t_user.columns.pwd.cipher-column=pwd
  35. spring.shardingsphere.rules.encrypt.tables.t_user.columns.pwd.encryptor-name=pwd-encryptor
  36. # Data encrypt algorithm configuration
  37. spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.type=AES
  38. spring.shardingsphere.rules.encrypt.encryptors.name-encryptor.props.aes-key-value=123456abc
  39. spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.type=AES
  40. spring.shardingsphere.rules.encrypt.encryptors.pwd-encryptor.props.aes-key-value=123456abc
  41. # Key generate strategy configuration
  42. spring.shardingsphere.rules.sharding.tables.t_user.key-generate-strategy.column=user_id
  43. spring.shardingsphere.rules.sharding.tables.t_user.key-generate-strategy.key-generator-name=snowflake
  44. # Sharding algorithm configuration
  45. spring.shardingsphere.rules.sharding.sharding-algorithms.default-database-strategy-inline.type=INLINE
  46. # The enumeration value of `ds_$->{user_id % 2}` is the name of the logical data source configured with readwrite-splitting
  47. spring.shardingsphere.rules.sharding.sharding-algorithms.default-database-strategy-inline.algorithm-expression=ds$->{user_id % 2}
  48. spring.shardingsphere.rules.sharding.sharding-algorithms.user-table-strategy-inline.type=INLINE
  49. spring.shardingsphere.rules.sharding.sharding-algorithms.user-table-strategy-inline.algorithm-expression=t_user_$->{user_id % 2}
  50. # Key generate algorithm configuration
  51. spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
  52. spring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=123
  53. # read query configuration
  54. # ds_0,ds_1 is the logical data source name of the readwrite-splitting
  55. spring.shardingsphere.rules.readwrite-splitting.data-sources.ds_0.write-data-source-name=write-ds0
  56. spring.shardingsphere.rules.readwrite-splitting.data-sources.ds_0.read-data-source-names=write-ds0-read0
  57. spring.shardingsphere.rules.readwrite-splitting.data-sources.ds_0.load-balancer-name=read-random
  58. spring.shardingsphere.rules.readwrite-splitting.data-sources.ds_1.write-data-source-name=write-ds1
  59. spring.shardingsphere.rules.readwrite-splitting.data-sources.ds_1.read-data-source-names=write-ds1-read0
  60. spring.shardingsphere.rules.readwrite-splitting.data-sources.ds_1.load-balancer-name=read-random
  61. # Load balance algorithm configuration
  62. spring.shardingsphere.rules.readwrite-splitting.load-balancers.read-random.type=RANDOM