-
Notifications
You must be signed in to change notification settings - Fork 16
/
datasource.xml
137 lines (128 loc) · 7.42 KB
/
datasource.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
default-autowire="byName">
<bean name="baseDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"
abstract="true">
<!--TODO: set the properties for your datasource-->
</bean>
<bean name="wDs00" parent="baseDataSource">
<property name="url" value="jdbc:mysql://127.0.0.1:3306/base_00?verifyServerCertificate=false&useSSL=true"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
</bean>
<bean name="rDs00" parent="baseDataSource">
<property name="url" value="jdbc:mysql://127.0.0.1:3306/base_00?verifyServerCertificate=false&useSSL=true"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
</bean>
<!-- rule是可选的,参数scRouteRule和tbRouteRule是也是可选的,如果没有配置在解析时返回原始表名 -->
<bean id="idRule" class="org.hellojavaer.ddal.ddr.shard.rule.SpelShardRouteRule">
<property name="scRouteRule" value="{scName}_{format('%02d', sdValue % 2)}"/>
<property name="tbRouteRule" value="{tbName}_{format('%04d', sdValue % 8)}"/>
</bean>
<!-- shardRouter是必选的,用于实现逻辑表名和路由规则的绑定 -->
<bean id="shardRouter" class="org.hellojavaer.ddal.ddr.shard.simple.SimpleShardRouter">
<property name="routeRuleBindings">
<list>
<bean class="org.hellojavaer.ddal.ddr.shard.simple.SimpleShardRouteRuleBinding">
<!-- scName是必选的,scName的路由结果会被用于在数据源管理器中做数据源选择 -->
<property name="scName" value="base"></property>
<!-- tbName是可选的,当没有配置tbName时,表示当前路由规则绑定到了当前schema下的所有表 -->
<!--<property name="tbName" value="user"></property>-->
<!-- rule是可选的,当没有配置时,解析时直接返回原表名 -->
<property name="rule" ref="idRule"></property>
<!-- sdKey是可选的,当没有配置时,通过ShardRouteContext获取路由信息 -->
<property name="sdKey" value="id"></property>
<!-- sdValues是可选的,sdValues用于将以上的配置转换为物理表,可用于扫表查询接口 -->
<property name="sdValues" value="[0..7]"></property>
</bean>
</list>
</property>
</bean>
<!-- shardParser是必选的,配置用于解析sql -->
<bean id="shardParser" class="org.hellojavaer.ddal.ddr.shard.simple.SimpleShardParser">
<property name="sqlParser">
<bean class="org.hellojavaer.ddal.ddr.sqlparse.cache.LRUSQLParserCache">
<property name="sqlParser">
<bean class="org.hellojavaer.ddal.jsqlparser.JSQLParser"/>
</property>
<property name="capacity" value="1000"/>
</bean>
</property>
<property name="shardRouter" ref="shardRouter"/>
</bean>
<!-- 数据源管理器(必选)有SingleDataSourceManager和DefaultReadWriteDataSourceManager,分别用于管理单数据源和多数据 -->
<!--<bean id="dataSourceManager" class="org.hellojavaer.ddal.ddr.datasource.manager.SingleDataSourceManager">-->
<!--<constructor-arg index="0" ref="wDs00"></constructor-arg>-->
<!--</bean>-->
<bean id="dataSourceManager"
class="org.hellojavaer.ddal.ddr.datasource.manager.rw.DefaultReadWriteDataSourceManager">
<property name="shardRouter" ref="shardRouter"/>
<!-- 配置只读数据源:可配置每个数据源的负载权重值 -->
<property name="readOnlyDataSources">
<list>
<bean class="org.hellojavaer.ddal.ddr.datasource.manager.rw.ReadOnlyDataSourceBinding">
<property name="scNames" value="base_0[0..1]"></property>
<property name="dataSources">
<list>
<bean class="org.hellojavaer.ddal.ddr.datasource.WeightedDataSource">
<property name="name" value="rDs00"></property>
<property name="weight" value="9"></property>
<property name="dataSource" ref="rDs00"></property>
</bean>
<bean class="org.hellojavaer.ddal.ddr.datasource.WeightedDataSource">
<property name="name" value="wDs00"></property>
<property name="weight" value="1"></property>
<property name="dataSource" ref="wDs00"></property>
</bean>
</list>
</property>
</bean>
</list>
</property>
<!-- 配置只写数据源-->
<property name="writeOnlyDataSources">
<list>
<bean class="org.hellojavaer.ddal.ddr.datasource.manager.rw.WriteOnlyDataSourceBinding">
<property name="scNames" value="base_0[0..1]"></property>
<property name="dataSource" ref="wDs00"></property>
</bean>
</list>
</property>
<!-- readOnlyDataSourceMonitorServer是可选的,该配置用于管理和调节只读数据源的负载 -->
<property name="readOnlyDataSourceMonitorServer">
<bean class="org.hellojavaer.ddal.ddr.datasource.manager.rw.monitor.mbean.MBeanReadOnlyDataSourceMonitorServer"></bean>
</property>
</bean>
<!-- ddrDataSource是必选的,用于包装组合底层分库分表的功能,对外提供统一接口 -->
<bean id="ddrDataSource" class="org.hellojavaer.ddal.ddr.datasource.jdbc.DefaultDDRDataSource">
<property name="dataSourceManager" ref="dataSourceManager"/>
<property name="shardParser" ref="shardParser"/>
</bean>
<!-- DefaultDBClusterManager(数据库集群配置)是可选的,如果移除集群配置需要将DefaultDDRDataSource配置的id改为dataSource -->
<bean id="dataSource" class="org.hellojavaer.ddal.ddr.cluster.DefaultDBClusterManager">
<property name="dataSources">
<map>
<entry key="default" value-ref="ddrDataSource"/>
</map>
</property>
</bean>
<!-- sequence是可选的,用于提供分布式主键的功能-->
<bean name="sequence" class="org.hellojavaer.ddal.sequence.SingleSequence" init-method="init">
<property name="schemaName" value="base"/>
<property name="tableName" value="user"/>
<property name="step" value="100"/>
<property name="cacheNSteps" value="5"/>
<property name="initTimeout" value="3000"/>
<property name="sequenceRangeGetter">
<bean class="org.hellojavaer.ddal.sequence.DatabaseSequenceRangeGetter" init-method="init">
<property name="dataSource" ref="wDs00"/>
<property name="scName" value="base_00"/>
</bean>
</property>
</bean>
</beans>