Logo
YAML Configuration

Overview #

YAML configuration provides interaction with DBPlusEngine Driver through configuration files. When used together with the governance module, the configuration of persistence in the configuration center is YAML format.

Note: the YAML configuration file supports more than 3MB of configuration content.

YAML configuration is the most common configuration mode, which can omit the complexity of programming and simplify user configuration.

Usage #

Import Maven Dependency #

<dependency>
    <groupId>org.apache.shardingsphere</groupId>
    <artifactId>shardingsphere-jdbc-core</artifactId>
    <version>${shardingsphere.version}</version>
</dependency>

YAML Format #

The DBPlusEngine-Driver YAML file consists of schema name, mode configuration, data source map, rule configurations and properties.

Note: the example connection pool is HikariCP, which can be replaced with other connection pools according to business scenarios.

# Alias of the datasource in JDBC.
# Through this parameter to connect, ShardingSphere-JDBC and ShardingSphere-Proxy.
# Default value: logic_db
schemaName (?):

mode:

dataSources:

rules:
- !FOO_XXX
    ...
- !BAR_XXX
    ...

props:
  key_1: value_1
  key_2: value_2

Please refer to Mode Confiugration for more mode details.

Please refer to Data Source Confiugration for more data source details.

Please refer to Rules Confiugration for more rule details.

Create Data Source #

The ShardingSphereDataSource created by YamlShardingSphereDataSourceFactory implements the standard JDBC DataSource interface.


File yamlFile = // Indicate YAML file
DataSource dataSource = YamlShardingSphereDataSourceFactory.createDataSource(yamlFile);

Use Data Source #

Same with Java API.

YAML Syntax Explanation #

!! means instantiation of that class

! means self-defined alias

- means one or multiple can be included

[] means array, can substitutable with - each other