Skip to content

FunCodingOfWe/elasticjob-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elasticjob-spring-boot-starter

封装es-job组件,方便可用

使用说明

  • 下载该项目,编译install
mvn install
  • 新项目中引入依赖
        <dependency>
            <groupId>com.kevin</groupId>
            <artifactId>elasticjob-spring-boot-starter</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
  • 开启elasticjob @EnableElasticJob
@EnableElasticJob
@SpringBootApplication
public class EsJobApplication {

    public static void main(String[] args) {
        SpringApplication.run(EsJobApplication.class, args);
    }

}
  • 配置对应的job
@Component
@ElasticJobConfig(
        name = "com.kevin.task.task.MySimpleJob",
        cron = "0/5 * * * * ?",
        description = "测试简单任务",
        overwrite = true,
        eventTraceRdbDataSource = "dataSource",
        shardingTotalCount = 2
)
public class MySimpleJob implements SimpleJob {
    @Override
    public void execute(ShardingContext shardingContext) {
        System.out.println("执行mysimpleJob====");
    }
}
  • 配置zk地址和namespace

elastic:
  job:
    zk:
      namespace: elastic-job
      serverLists: 127.0.0.1:2181

具体使用样例请看demo