1. 部署
就是这个地址: https://gitee.com/xuxueli0323/xxl-job
由于xxl-job的思想是 调度中心负责调度任务,然后有执行器负责接受调度的信息,然后根据调度,执行任务中的具体逻辑
将 xl-job-admin 启动起来,操作xl-job-admin这个文件夹下的配置文件即可:
创建数据库
执行sql文件
修改yml配置
启动这个服务
访问,http://127.0.0.1:8080/xxl-job-admin/
并登录 admin/123456
2.SpringBoot集成
1引入xxl-job核心依赖
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.1</version>
</dependency>
2 创建服务,配置yml
xxl.job.admin.addresses = http://127.0.0.1:8080/xxl-job-admin
xxl.job.executor.port = 9999
xxl.job.executor.appname = xxljob
xxl.job.executor.logpath = /data/applogs/xxl-job/jobhandler
xxl.job.executor.logretentiondays = 30
3 配置job
@Slf4j
@Configuration
public class XxlJobConfig {
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.executor.appname}")
private String appName;
@Value("${xxl.job.executor.port}")
private int port;
@Value("${xxl.job.executor.logpath}")
private String logPath;
@Value("${xxl.job.executor.logretentiondays}")
private int logRetentionDays;
@Bean
@ConditionalOnExpression("${xxl-job.enabled:true}")
public XxlJobSpringExecutor xxlJobSpringExecutor() {
log.info("xxl-job config init =====");
XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
executor.setAdminAddresses(adminAddresses);
executor.setAppname(appName);
executor.setPort(port);
executor.setLogPath(logPath);
executor.setLogRetentionDays(logRetentionDays);
return executor;
}
}
4 测试
@Component
public class TestJob {
// 测试xxlJob是否配置成功
@XxlJob(value = "firstTestJob")
public ReturnT<String> firstTestJob(String param){
System.out.println("执行触发器:"+param);
return ReturnT.SUCCESS;
}
}