Logo
YAML Configuration

Introduction #

YAML provides a means of interacting with DBPlusEngine-Driver via configuration files. When used with the Governance module, the configuration persisted in the Configuration Centre is done in YAML format.

Note: YAML configuration files support configuration content over 3MB.

YAML configuration is the most common configuration method, eliminating the need for programming complexity and simplifying user configuration.

Usage steps #

Introduce Maven dependency #

<dependency>
    <groupId>com.sphere-ex</groupId>
    <artifactId>shardingsphere-jdbc-core</artifactId>
    <version>${shardingsphere.version}</version>
</dependency>

Configure YAML #

The YAML configuration file for DBPlusEngine-Driver consists of a Schema name, a runtime schema, a collection of data sources, a collection of rules, and a configuration of attributes.

# Alias for the data source in JDBC. In cluster mode, use this parameter to associate DBPlusEngine-Driver with DBPlusEngine-Proxy. 
# Default value: logic_db
databaseName (?):

mode:

dataSources:

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

props:
  key_1: value_1
  key_2: value_2

SeeMode Configurationfor details of the mode.

SeeData Source Configurationfor details of the data source.

SeeRule Configurationfor details of the rules.

Build data sources #

The ShardingSphereDataSource created by the YamlShardingSphereDataSourceFactory factory implements DataSource, a standard interface from JDBC.


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

Use data sources #

Used in the same way as the Java API.

Syntax notes #

!! indicates that the class is instantiated

! indicates custom aliases

- indicates that it can contain one or more

[] indicates an array and can be used interchangeably with the minus sign

Support using Apollo to store yaml configuration #

When using the Apollo loader, you need to add the corresponding apollo pom dependency. The currently adapted version is 1.9.0, as follows:

<dependency>
    <groupId>com.ctrip.framework.apollo</groupId>
    <artifactId>apollo-client</artifactId>
    <version>${apollo.version}</version>
</dependency>