Read/write splitting YAML configuration is highly readable. The YAML format enables you to quickly understand the dependencies between read/write sharding rules. ShardingSphere automatically creates the ShardingSphereDataSource object according to the YAML configuration, which reduces unnecessary coding for users.
rules: - !READWRITE_SPLITTING dataSources: <data_source_name> (+): # Logic data source name of readwrite-splitting, which uses Groovy's Row Value Expressions SPI implementation to parse by default write_data_source_name: # Write data source name, which uses Groovy's Row Value Expressions SPI implementation to parse by default read_data_source_names: # Read data source names, multiple data source names separated with comma, which uses Groovy's Row Value Expressions SPI implementation to parse by default transactionalReadQueryStrategy (?): # Routing strategy for read query within a transaction, values include: PRIMARY (to primary), FIXED (to fixed data source), DYNAMIC (to any data source), default value: DYNAMIC loadBalancerName: # Load balance algorithm name # Load balance algorithm configuration loadBalancers: <load_balancer_name> (+): # Load balance algorithm name type: # Load balance algorithm type props: # Load balance algorithm properties # ...
Please refer to Built-in Load Balance Algorithm List for more details about type of algorithm.
rules: - !READWRITE_SPLITTING dataSources: readwrite_ds: writeDataSourceName: write_ds readDataSourceNames: - read_ds_0 - read_ds_1 transactionalReadQueryStrategy: PRIMARY loadBalancerName: random loadBalancers: random: type: RANDOM