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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM