Mode

Background

The default configuration uses standalone mode.

Parameters Explained

Standalone Mode

Namespace:http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone/repository-5.1.1.xsd <standalone:repository />

NameTypeDescription
idPropertyPersistent repository Bean name
typePropertyPersistent repository Type
props (?)TagProperties required for persistent repository

Namespace:http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster/repository-5.1.1.xsd

<cluster:repository />

NameTypeDescription
idPropertyPersistent repository Bean name
typePropertyPersistent repository Type
namespacePropertyRegistry Center namespace
server-listsPropertyRegistry Center Link
props (?)TagProperties required for persistent repository

Tips:

  1. For production environments, it is recommended to use cluster mode deployment.
  2. The ZooKeeper registry center is recommended for cluster mode deployment.
  3. If there is configuration information in the ZooKeeper, please refer to the config information there.

Operating Procedures

Introduce MAVEN dependency

  1. <dependency>
  2. <groupId>org.apache.shardingsphere</groupId>
  3. <artifactId>shardingsphere-jdbc-core-spring-namespace</artifactId>
  4. <version>${latest.release.version}</version>
  5. </dependency>

Note: Please change ${latest.release.version} to the actual version number.

Configuration Example

Standalone Mode

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
  5. xmlns:standalone="http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://shardingsphere.apache.org/schema/shardingsphere/datasource
  9. http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
  10. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone
  11. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/standalone/repository.xsd">
  12. <standalone:repository id="standaloneRepository" type="JDBC">
  13. </standalone:repository>
  14. <shardingsphere:data-source id="ds" database-name="foo_db" data-source-names="..." rule-refs="..." >
  15. <shardingsphere:mode type="Standalone" repository-ref="standaloneRepository" />
  16. </shardingsphere:data-source>
  17. </beans>

Cluster Mode

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:shardingsphere="http://shardingsphere.apache.org/schema/shardingsphere/datasource"
  5. xmlns:cluster="http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://shardingsphere.apache.org/schema/shardingsphere/datasource
  9. http://shardingsphere.apache.org/schema/shardingsphere/datasource/datasource.xsd
  10. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster
  11. http://shardingsphere.apache.org/schema/shardingsphere/mode-repository/cluster/repository.xsd">
  12. <cluster:repository id="clusterRepository" type="Zookeeper" namespace="regCenter" server-lists="localhost:3182">
  13. <props>
  14. <prop key="max-retries">3</prop>
  15. <prop key="operation-timeout-milliseconds">1000</prop>
  16. </props>
  17. </cluster:repository>
  18. <shardingsphere:data-source id="ds" database-name="foo_db" data-source-names="..." rule-refs="...">
  19. <shardingsphere:mode type="Cluster" repository-ref="clusterRepository" />
  20. </shardingsphere:data-source>
  21. </beans>

Relevant References