zoukankan      html  css  js  c++  java
  • 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 .......

  • 相关阅读:
    数列(codevs 1141)
    Circle(codevs 3134)
    Jam的计数法(codevs 1140)
    水果姐逛水果街Ⅰ(codevs 3304)
    引水入城(codevs 1066)
    Vigenère 密码(luogu 1079)
    铺地毯(luogu 1003)
    SSO之CAS基础及应用视频教程(1)
    Spark高速入门指南(Quick Start Spark)
    python爬虫CSDN文章抓取
  • 原文地址:https://www.cnblogs.com/qinls/p/10478833.html
Copyright © 2011-2022 走看看