Hi All community friends:
now,There are a lot of the same datasource  config when we use 
sharding,master-slave datasource.

In springboot project we can configruation like this :
-------------------------------------------------------------------------------------------------------------
spring.shardingsphere.datasource.ds_master_0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0
spring.shardingsphere.datasource.ds_master_0.username=root
spring.shardingsphere.datasource.ds_master_0.password=

spring.shardingsphere.datasource.ds_master_0_slave_0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0_slave_0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0
spring.shardingsphere.datasource.ds_master_0_slave_0.username=root
spring.shardingsphere.datasource.ds_master_0_slave_0.password=

spring.shardingsphere.datasource.ds_master_0_slave_1.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds_master_0_slave_1.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds_master_0_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1?
spring.shardingsphere.datasource.ds_master_0_slave_1.username=root
spring.shardingsphere.datasource.ds_master_0_slave_1.password=
-----------------------------------------------------------------------------------------------------------------------------------------------------

We're will optimize after like this:

--------------------------------------------------------------------------------------------------------------------------------------------------
spring.shardingsphere.datasource.common.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.common.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.common.username=root
spring.shardingsphere.datasource.common.password=

spring.shardingsphere.datasource.ds_master_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0

spring.shardingsphere.datasource.ds_master_0_slave_0.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_0

spring.shardingsphere.datasource.ds_master_0_slave_1.jdbc-url=jdbc:mysql://localhost:3306/demo_ds_master_0_slave_1
-----------------------------------------------------------------------------------------------------------------------------------------------


In yaml we configruation like this:

---------------------------------------------------------------------------------------------------
dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
    username: root
    password:
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
  ds_1:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
    username: root
    password:
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
   maxPoolSize: 50
---------------------------------------------------------------------------------------------------------

We're will optimize after like this:

------------------------------------------------------------------------------------------------------------
dataSourceCommon:
  username: root
  password:
  connectionTimeoutMilliseconds: 30000
  idleTimeoutMilliseconds: 60000
  maxLifetimeMilliseconds: 1800000
  maxPoolSize: 50
  minPoolSize: 1
  maintenanceIntervalMilliseconds: 30000

dataSources:
  ds_0:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
  ds_1:
    url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
------------------------------------------------------------------------------------------------------

After the optimization , User configuration will be greatly simplified, 
especially when users need to configure multiple datasources.

Thanks ??Looking forward to your reply??
 
Kind regards,
xiaoyu

Reply via email to