Background
Build the running mode through Java API.
Parameters
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 |
Standalone Persist Configuration
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 |
Cluster Persist Configuration
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 |
Notes
- Cluster mode deployment is recommended for production environment.
- The
ZooKeeper
registry center is recommended for cluster mode deployment. - If there is configuration information in the
ZooKeeper
, please refer to the config information there.
Procedure
Introduce Maven Dependency
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>${latest.release.version}</version>
</dependency>
Notice: Please change
${latest.release.version}
to the actual version.
Sample
Standalone Mode
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()));
}
Cluster Mode (Recommended)
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()));
}
Related References
- Installation and Usage of ZooKeeper Registry Center
- Please refer to Builtin Persist Repository List for more details about type of repository.
当前内容版权归 ShardingSphere 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ShardingSphere .