elasticjob 当当的分布式定时任务管理
elasticjob官网:http://elasticjob.io/index_zh.html
https://blog.csdn.net/a13627210064/article/details/81201800
https://www.jianshu.com/p/8411504c53a3
https://blog.csdn.net/yangliuhbhd/article/details/80902212
一 管理平台安装
1.在github https://github.com/elasticjob/elastic-job-lite
上导入项目到本地
2.http://localhost:8899/# 访问默认的端口
3. 注册中心 zk 安装配置上
注意:命名空间一定是配置定时任务中命名的一致
4. 可以看到相应的作业任务
二 项目中配置定时任务
1.pom添加依赖
<!-- 引入elastic-job-lite springboot核心模块 --> <dependency> <groupId>com.github.kuhn-he</groupId> <artifactId>elastic-job-lite-spring-boot-starter</artifactId> <version>2.1.5</version> </dependency>
2.yml 中配置参数
elaticjob: zookeeper: server-lists: localhost:2181 namespace: my-project-name
3.建一个任务类 LateInfoTask
@Slf4j @Component //springboot整合主要就是注解了。这里指定一下相关配偶。服务链接到zk上。 控制台配置之后就看得到啦,之后也可以在控制台上手动修改一些相关配置 @ElasticSimpleJob(cron = "0/3 * * * * ? *", jobName = "lateInfoTask", shardingTotalCount = 2, jobParameter = "测试参数", shardingItemParameters = "0=A,1=B") public class LateInfoTask implements SimpleJob { @Autowired private UserService userService; @Override public void execute(ShardingContext shardingContext) { List<User> allUser = userService.findAllUser(1, 10); for (User user : allUser) { log.info("对象:{}", user); } System.out.println(new Date() + " job名称 = " + shardingContext.getJobName() + "分片数量" + shardingContext.getShardingTotalCount() + "当前分区" + shardingContext.getShardingItem() + "当前分区名称" + shardingContext.getShardingParameter() + "当前自定义参数" + shardingContext.getJobParameter() + "============start================="); // 原文:https://blog.csdn.net/u013018994/article/details/76212229 } }
后期整理 cloud 相关的 job .......
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步