zoukankan      html  css  js  c++  java
  • SpringBoot 快速集成 Elastic Job


    一、引入依赖

    <dependency>
        <groupId>com.github.kuhn-he</groupId>
        <artifactId>elastic-job-lite-spring-boot-starter</artifactId>
        <version>2.1.53</version>
    </dependency>

    二、配置Elastic Job

    #elastic-job
    elaticjob.zookeeper.server-lists=127.0.0.1:2181
    elaticjob.zookeeper.namespace=bounter-job

    三、开发Job类

    package cn.bounter.job.elasticjob;
    
    import com.dangdang.ddframe.job.api.ShardingContext;
    import com.dangdang.ddframe.job.api.simple.SimpleJob;
    import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
    import org.springframework.stereotype.Component;
    
    //Job configuration annotation
    @ElasticSimpleJob(cron="*/3 * * * * ?", shardingTotalCount=2)
    @Component
    public class AppJob implements SimpleJob {
        @Override
        public void execute(ShardingContext shardingContext) {
            switch (shardingContext.getShardingItem()) {
                case 0:
                    System.out.println("hello from shard 0");
                    break;
                case 1:
                    System.out.println("hello from shard 1");
                    break;
            }
        }
    }

    四、启动SpringBoot应用,观察控制台输出

    这就是所有步骤了,是不是很简单哉!那就赶快自己试试吧!
     
    需要源代码的见Github传送门:
  • 相关阅读:
    弱网环境测试点总结
    【CMDB】高级配置
    【CMDB】获取服务器数据
    Centos部属前后端项目
    Centos部署项目
    Django
    nginx反向代理和负载均衡
    nginx的配置
    centos7 安装nginx
    centos7 安装Virtualenv
  • 原文地址:https://www.cnblogs.com/gdufs/p/10925420.html
Copyright © 2011-2022 走看看