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

  • 相关阅读:
    佛洛依德
    Python2.7利用Tesseract进行中英文图像识别
    批量生成二维码打包成exe文件
    python基础5—文件 | json序列化
    python基础6—(高阶,匿名,偏)函数 | 装饰器
    python基础4—面向对象
    python基础2—集合框架
    一不小心翻车了-(angularjs 1.6X) 由Eventbus使用异常说起
    简单说下js闭包之setTimeout
    html5上传本地图片,在线预览及裁剪(filereader,canvas)
  • 原文地址:https://www.cnblogs.com/qinls/p/10478833.html
Copyright © 2011-2022 走看看