version: "3"
services:
job:
image: xuxueli/xxl-job-admin:2.3.0
ports:
- "8080:8080"
volumes:
- "./tmp:/data/applogs"
- "./application.properties:/application.properties"
mysql:
image: mysql:5.7
volumes:
- ./mysql:/var/lib/mysql
ports:
- 3316:3306
command: --sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION --lower_case_table_names=1
environment:
MYSQL_ROOT_PASSWORD: demoapp
TZ: Asia/Shanghai
启动之后,需要执行sql 初始化(参考)默认密码: admin 123456
效果
@XxlJob("shardingJobHandler")
public void shardingJobHandler() throws Exception {
// 分片参数
int shardIndex = XxlJobHelper.getShardIndex();
int shardTotal = XxlJobHelper.getShardTotal();
XxlJobHelper.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);
// 业务逻辑
for (int i = 0; i < shardTotal; i++) {
if (i == shardIndex) {
XxlJobHelper.log("第 {} 片, 命中分片开始处理", i);
} else {
XxlJobHelper.log("第 {} 片, 忽略", i);
}
}
}
xxljob 使用是比较简单的,但是提供的能力还是很不错的,官方文档很比较完备可以方便学习
https://github.com/rongfengliang/xxljob-docker-compose
https://github.com/xuxueli/xxl-job