一、快速开始
1、加入jar
<dependency>
<groupId>com.github.kuhn-he</groupId>
<artifactId>elastic-job-lite-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
2、配置zookeeper
elaticjob.zookeeper.server-lists=106.13.123.121:2181
elaticjob.zookeeper.namespace=my-project
3、编写定时任务
@ElasticSimpleJob(cron = "* * * * * ?", jobName = "test123", shardingTotalCount = 2, jobParameter = "测试参数", shardingItemParameters = "0=A,1=B")
@Component
public class MySimpleJob implements SimpleJob {
@Override
public void execute(ShardingContext shardingContext) {
//System.out.println(String.format("Thread ID: %s, 任务总片数: %s,当前分片项: %s.当前参数: %s,当前任务名称: %s.当前任务参数: %s",Thread.currentThread().getId(),shardingContext.getShardingTotalCount(),shardingContext.getShardingItem(),shardingContext.getShardingParameter(),shardingContext.getJobName(),shardingContext.getJobParameter()));
System.out.println(LocalDateTime.now());
}
}
4、启动项目
二、elastic-job-lite-console运维平台的部署使用
1、下载zip包elastic-job-lite-console;
2、解压并执行bin\start.sh;
4、初始管理员账号root 密码root ;可通过conf\auth.properties修改用户名及密码。
以上启动方式关闭客户端,程序即关闭.可使用nohup ./bin/start.sh &命令让程序一直在后台运行 可通过添加注册中心进行操作,该后台支持以下功能
- 查看作业以及服务器状态
- 快捷的修改以及删除作业设置
- 启用和禁用作业
- 跨注册中心查看作业
- 查看作业运行轨迹和运行状态
评论区