mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-02-05 18:15:28 +08:00
拆分独立微服务测试模块jeecg-cloud-test,提供更多测试示例: 分布式事务、分库分表、mq、xxljob等
This commit is contained in:
@ -29,12 +29,12 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
private IShardingSysLogService shardingSysLogService;
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* 单库分表
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/add")
|
||||
@AutoLog(value = "分库分表添加")
|
||||
@ApiOperation(value = "分库分表添加", notes = "分库分表添加")
|
||||
@PostMapping(value = "/test1")
|
||||
@AutoLog(value = "单库分表")
|
||||
@ApiOperation(value = "单库分表", notes = "分库分表添加")
|
||||
public Result<?> add() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ShardingSysLog shardingSysLog = new ShardingSysLog();
|
||||
@ -45,5 +45,22 @@ public class JeecgShardingDemoController extends JeecgController<ShardingSysLog,
|
||||
}
|
||||
return Result.OK();
|
||||
}
|
||||
/**
|
||||
* 双库分表
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/test2")
|
||||
@AutoLog(value = "双库分表")
|
||||
@ApiOperation(value = "双库分表", notes = "双库分表")
|
||||
public Result<?> test2() {
|
||||
for (int i = 20; i <= 30; i++) {
|
||||
ShardingSysLog shardingSysLog = new ShardingSysLog();
|
||||
shardingSysLog.setLogContent("双库分表测试");
|
||||
shardingSysLog.setLogType(i);
|
||||
shardingSysLog.setOperateType(i);
|
||||
shardingSysLogService.save(shardingSysLog);
|
||||
}
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,9 +3,10 @@ spring:
|
||||
props:
|
||||
sql-show: true
|
||||
datasource:
|
||||
#添加分库数据源
|
||||
ds0:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://localhost:3300/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
password: root
|
||||
@ -26,7 +27,8 @@ spring:
|
||||
table-classbased:
|
||||
props:
|
||||
strategy: standard
|
||||
algorithmClassName: org.jeecg.modules.test.sharding.algorithm.StandardModTableShardAlgorithm
|
||||
# 自定义标准分配算法
|
||||
algorithmClassName: org.jeecg.modules.demo.sharding.algorithm.StandardModTableShardAlgorithm
|
||||
type: CLASS_BASED
|
||||
tables:
|
||||
# 逻辑表名称
|
||||
@ -38,5 +40,5 @@ spring:
|
||||
standard:
|
||||
# 分片算法名称
|
||||
sharding-algorithm-name: table-classbased
|
||||
# 分片列名称
|
||||
# 分片列名称(对应数据库字段)
|
||||
sharding-column: log_type
|
||||
@ -0,0 +1,72 @@
|
||||
# 双库分表配置
|
||||
spring:
|
||||
shardingsphere:
|
||||
props:
|
||||
sql-show: true
|
||||
datasource:
|
||||
ds0:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/jeecg-boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
username: root
|
||||
password: root
|
||||
ds1:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/jeecg-boot2?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
username: root
|
||||
password: root
|
||||
names: ds0,ds1
|
||||
# 规则配置
|
||||
rules:
|
||||
replica-query:
|
||||
# 负载均衡算法
|
||||
load-balancers:
|
||||
round-robin:
|
||||
type: ROUND_ROBIN
|
||||
props:
|
||||
default: 0
|
||||
data-sources:
|
||||
prds:
|
||||
primary-data-source-name: ds0
|
||||
replica-data-source-names: ds1
|
||||
load-balancer-name: round_robin
|
||||
sharding:
|
||||
# 配置绑定表,每一行为一组,绑定表会提高查询效率
|
||||
binding-tables:
|
||||
- sys_log
|
||||
# 分布式序列算法配置
|
||||
key-generators:
|
||||
snowflake:
|
||||
type: SNOWFLAKE
|
||||
props:
|
||||
worker-id: 123
|
||||
# 分片算法配置
|
||||
sharding-algorithms:
|
||||
table-classbased:
|
||||
props:
|
||||
strategy: standard
|
||||
algorithmClassName: org.jeecg.modules.test.sharding.algorithm.StandardModTableShardAlgorithm
|
||||
type: CLASS_BASED
|
||||
# 通过operate_type取模的方式确定数据落在哪个库
|
||||
database-inline:
|
||||
type: INLINE
|
||||
props:
|
||||
algorithm-expression: ds$->{operate_type % 2}
|
||||
tables:
|
||||
# 逻辑表名称
|
||||
sys_log:
|
||||
#配置具体表的数据节点
|
||||
actual-data-nodes: ds$->{0..1}.sys_log$->{0..1}
|
||||
# 分库策略
|
||||
database-strategy:
|
||||
standard:
|
||||
sharding-column: operate_type
|
||||
sharding-algorithm-name: database-inline
|
||||
# 分表策略
|
||||
table-strategy:
|
||||
standard:
|
||||
# 分片算法名称
|
||||
sharding-algorithm-name: table-classbased
|
||||
# 分片列名称
|
||||
sharding-column: log_type
|
||||
Reference in New Issue
Block a user