Build the running mode through Java API.
Class name: org.apache.shardingsphere.infra.config.mode.ModeConfiguration
Attributes:
Name | DataType | Description | Default Value |
---|---|---|---|
type | String | Type of mode configuration Values could be: Standalone or Cluster |
Standalone |
repository | PersistRepositoryConfiguration | Persist repository configuration Standalone type uses StandalonePersistRepositoryConfiguration Cluster type uses ClusterPersistRepositoryConfiguration |
Class name: org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryConfiguration
Attributes:
Name | DataType | Description |
---|---|---|
type | String | Type of persist repository |
props | Properties | Properties of persist repository |
Class name: org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration
Attributes:
Name | Data Type | Description |
---|---|---|
type | String | Type of persist repository |
namespace | String | Namespace of registry center |
server-lists | String | Server lists of registry center |
props | Properties | Properties of persist repository |
ZooKeeper
registry center is recommended for cluster mode deployment.ZooKeeper
, please refer to the config information there.<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core</artifactId>
<version>${latest.release.version}</version>
</dependency>
Notice: Please change
${latest.release.version}
to the actual version.
ModeConfiguration modeConfig = createModeConfiguration();
Map<String, DataSource> dataSourceMap = ... // Building real data sources
Collection<RuleConfiguration> ruleConfigs = ... // Build specific rules
Properties props = ... // Build property configuration
DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(databaseName, modeConfig, dataSourceMap, ruleConfigs, props);
private ModeConfiguration createModeConfiguration() {
return new ModeConfiguration("Standalone", new StandalonePersistRepositoryConfiguration("JDBC", new Properties()));
}
ModeConfiguration modeConfig = createModeConfiguration();
Map<String, DataSource> dataSourceMap = ... // Building real data sources
Collection<RuleConfiguration> ruleConfigs = ... // Build specific rules
Properties props = ... // Build property configuration
DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(databaseName, modeConfig, dataSourceMap, ruleConfigs, props);
private ModeConfiguration createModeConfiguration() {
return new ModeConfiguration("Cluster", new ClusterPersistRepositoryConfiguration("ZooKeeper", "governance-sharding-db", "localhost:2181", new Properties()));
}