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 .......