官网地址:https://www.xuxueli.com/xxl-job
一、搭建好xxlJob平台,一般都已经搭建完毕
二、接入xxljob的步骤
引入依赖
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.0.1</version>
</dependency>
在application.properties或者application.yml 中添加xxljob的相关配置
#xxlJob
### 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
xxl.job.admin.addresses=http://xxl-job:8080/xxl-job-admin/
### 执行器通讯TOKEN [选填]:非空时启用;
xxl.job.admin.accessToken=
### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
xxl.job.admin.appname= fantasyci-xxl-job
### 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
xxl.job.admin.ip=
### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
xxl.job.admin.port=9999
### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
xxl.job.admin.logpath=root/logs/xxl-job/jobhandler
### 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
xxl.job.admin.logretentiondays=30
写一个配置类,进行读取xxljsob中的配置 ```java package qa.config;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;
/**
- @author Alex
- @date 2021/9/18 5:18 下午
-
*/
@Slf4j
@Data
@Configuration
@ConditionalOnProperty(
prefix = "xxl.job.admin",
name = {"addresses"}
) @ConfigurationProperties(prefix = “xxl.job.admin”) public class XxlJobConfiguration { private String addresses; private String appName; private String ip; private int port; private String accessToken; private String logPath; private int logRetentionDays;
@Bean(
initMethod = "start",
destroyMethod = "destroy"
) public XxlJobSpringExecutor xxlJobSpringExecutor() {
log.info(">>>>>>>>>>> xxl-job config init...");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(this.addresses);
xxlJobSpringExecutor.setAppName(this.appName);
xxlJobSpringExecutor.setIp(this.ip);
xxlJobSpringExecutor.setPort(this.port);
xxlJobSpringExecutor.setAccessToken(this.accessToken);
xxlJobSpringExecutor.setLogPath(this.logPath);
xxlJobSpringExecutor.setLogRetentionDays(this.logRetentionDays);
return xxlJobSpringExecutor;
} }
3. bean模式,编写一个job,新建一个task包,新建一个FlowHandler类
```java
@Slf4j
@JobHandler("runFlowHandler")
@Service
public class FlowHandler extends IJobHandler {
@Autowired
private SuiteService suiteService;
@Override
public ReturnT<String> execute(String s) {
suiteService.runTestSuite("fantasyrn_flow.xml", "fantasy", "0000,0001", "no_baranch", "");
return ReturnT.SUCCESS;
}
}
- 按照官网去操作即可了