| <?xml version="1.0" encoding="utf-8" standalone="yes"?> |
| <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
| <channel> |
| <title>分布式治理 on ShardingSphere</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/</link> |
| <description>Recent content in 分布式治理 on ShardingSphere</description> |
| <generator>Hugo -- gohugo.io</generator> |
| <language>en-us</language> |
| |
| <atom:link href="https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/index.xml" rel="self" type="application/rss+xml" /> |
| |
| |
| <item> |
| <title>使用 Java API</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/java-api/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/java-api/</guid> |
| <description>引入 Maven 依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-jdbc-governance&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 ZooKeeper 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-zookeeper-curator&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 Etcd 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-etcd&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; 规则配置 以下示例将 ZooKeeper 作为配置中心和注册中心。 |
| // 省略配置数据源以及规则 // ... // 配置配置/注册中心 GovernanceCenterConfiguration configuration = new GovernanceCenterConfiguration(&#34;Zookeeper&#34;, &#34;localhost:2181&#34;, new Properties()); // 配置治理 Map&lt;String, CenterConfiguration&gt; configurationMap = new HashMap&lt;String, CenterConfiguration&gt;(); configurationMap.put(&#34;governance-shardingsphere-data-source&#34;, configuration); // 创建 GovernanceShardingSphereDataSource DataSource dataSource = GovernanceShardingSphereDataSourceFactory.createDataSource( createDataSourceMap(), createShardingRuleConfig(), new Properties(), new GovernanceConfiguration(&#34;shardingsphere-governance&#34;, configurationMap, true)); 使用 GovernanceShardingSphereDataSource 通过 GovernanceShardingSphereDataSourceFactory 工厂创建的 GovernanceShardingSphereDataSource 实现自 JDBC 的标准接口 DataSource。 可通过 DataSource 选择使用原生 JDBC,或JPA, MyBatis 等 ORM 框架。</description> |
| </item> |
| |
| <item> |
| <title>使用 YAML 配置</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/yaml/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/yaml/</guid> |
| <description>引入 Maven 依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-jdbc-governance&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 ZooKeeper 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-zookeeper-curator&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 Etcd 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-etcd&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; 规则配置 以下示例将 ZooKeeper 作为配置中心和注册中心。 |
| governance: name: governance_ds registryCenter: type: Zookeeper serverLists: localhost:2181 overwrite: true // 创建 GovernanceShardingSphereDataSource DataSource dataSource = YamlGovernanceShardingSphereDataSourceFactory.createDataSource(yamlFile); 使用 GovernanceShardingSphereDataSource 通过 YamlGovernanceShardingSphereDataSourceFactory 工厂创建的 GovernanceShardingSphereDataSource 实现自 JDBC 的标准接口 DataSource。 可通过 DataSource 选择使用原生 JDBC,或JPA, MyBatis 等 ORM 框架。 |
| 以原生 JDBC 使用方式为例:</description> |
| </item> |
| |
| <item> |
| <title>使用 Spring Boot Starter</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/spring-boot-starter/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/spring-boot-starter/</guid> |
| <description>引入 Maven 依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-jdbc-governance-spring-boot-starter&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 ZooKeeper 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-zookeeper-curator&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 Etcd 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-etcd&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; 规则配置 spring.shardingsphere.governance.name=governance-spring-boot-shardingsphere-test spring.shardingsphere.governance.registry-center.type=Zookeeper spring.shardingsphere.governance.registry-center.server-lists=localhost:2181 spring.shardingsphere.governance.overwrite=true 在 Spring 中使用 GovernanceShardingSphereDataSource 直接通过注入的方式即可使用 GovernanceShardingSphereDataSource;或者将 GovernanceShardingSphereDataSource 配置在JPA, MyBatis 等 ORM 框架中配合使用。 |
| @Resource private DataSource dataSource; </description> |
| </item> |
| |
| <item> |
| <title>使用 Spring 命名空间</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/spring-namespace/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/usage/governance/spring-namespace/</guid> |
| <description>引入Maven依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-jdbc-governance-spring-namespace&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 ZooKeeper 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-zookeeper-curator&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; &lt;!-- 使用 Etcd 时,需要引入此模块 --&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-governance-repository-etcd&lt;/artifactId&gt; &lt;version&gt;${shardingsphere.version}&lt;/version&gt; &lt;/dependency&gt; 规则配置 &lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;beans xmlns:xsi=&#34;http://www.w3.org/2001/XMLSchema-instance&#34; xmlns:governance=&#34;http://shardingsphere.apache.org/schema/shardingsphere/governance&#34; xmlns=&#34;http://www.springframework.org/schema/beans&#34; xsi:schemaLocation=&#34;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://shardingsphere.apache.org/schema/shardingsphere/governance http://shardingsphere.apache.org/schema/shardingsphere/governance/governance.xsd&#34;&gt; &lt;util:properties id=&#34;instance-properties&#34;&gt; &lt;prop key=&#34;max-retries&#34;&gt;3&lt;/prop&gt; &lt;prop key=&#34;operation-timeout-milliseconds&#34;&gt;3000&lt;/prop&gt; &lt;/util:properties&gt; &lt;governance:reg-center id=&#34;regCenter&#34; type=&#34;Zookeeper&#34; server-lists=&#34;localhost:2181&#34; /&gt; &lt;governance:data-source id=&#34;shardingDatabasesTablesDataSource&#34; data-source-names=&#34;demo_ds_0, demo_ds_1&#34; reg-center-ref=&#34;regCenter&#34; config-center-ref=&#34;configCenter&#34; rule-refs=&#34;shardingRule&#34; overwrite=&#34;true&#34; /&gt; &lt;governance:data-source id=&#34;replicaQueryDataSource&#34; data-source-names=&#34;demo_primary_ds, demo_replica_ds_0, demo_replica_ds_1&#34; reg-center-ref=&#34;regCenter&#34; config-center-ref=&#34;configCenter&#34; rule-refs=&#34;replicaQueryRule&#34; overwrite=&#34;true&#34; /&gt; &lt;governance:data-source id=&#34;encryptDataSource&#34; data-source-names=&#34;demo_ds&#34; reg-center-ref=&#34;regCenter&#34; config-center-ref=&#34;configCenter&#34; rule-refs=&#34;encryptRule&#34; overwrite=&#34;true&#34; &gt; &lt;props&gt; &lt;prop key=&#34;query-with-cipher-column&#34;&gt;true&lt;/prop&gt; &lt;/props&gt; &lt;/governance:data-source&gt; &lt;/beans&gt; 在 Spring 中使用 GovernanceShardingSphereDataSource 直接通过注入的方式即可使用 GovernanceShardingSphereDataSource;或者将 GovernanceShardingSphereDataSource 配置在JPA, MyBatis 等 ORM 框架中配合使用。</description> |
| </item> |
| |
| </channel> |
| </rss> |