XXL-JOB 配置
概述
XXL-JOB 是一个分布式任务调度平台,Widiazine SCRM 通过 widiazine-xxljob 模块提供自动配置。
启用 XXL-JOB
1. 添加依赖
<dependency>
<groupId>org.widiazine.boot</groupId>
<artifactId>widiazine-xxljob</artifactId>
<version>${widiazine.version}</version>
</dependency>2. 添加注解
在启动类上添加 @EnableXxlJob 注解:
@SpringBootApplication
@EnableXxlJob
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}配置文件
application.yml
widiazine:
xxljob:
enabled: true
adminAddresses: http://192.168.1.100:8080/xxl-job-admin
appname: widiazine-cloud-system
accessToken: default_token
logPath: /data/applogs/xxl-job/jobhandler
logRetentionDays: 30配置属性说明
| 属性 | 必填 | 默认值 | 说明 |
|---|---|---|---|
| enabled | 否 | true | 是否启用 XXL-JOB |
| adminAddresses | 是 | - | 调度中心地址 |
| appname | 是 | - | 执行器名称 |
| accessToken | 否 | - | 通讯令牌 |
| logPath | 是 | - | 日志路径 |
| logRetentionDays | 否 | 30 | 日志保留天数 |
自动配置原理
XxlJobConfiguration
@Configuration
@EnableConfigurationProperties({XxlJobProperties.class})
@ConditionalOnProperty(
value = {"widiazine.xxljob.enabled"},
havingValue = "true",
matchIfMissing = true
)
public class XxlJobConfiguration {
@Bean
@ConditionalOnClass
public XxlJobSpringExecutor xxlJobExecutor() {
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppname());
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath());
xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays());
return xxlJobSpringExecutor;
}
}Nacos 配置
在 Nacos 中配置(widiazine-{module}.yaml):
widiazine:
xxljob:
enabled: true
adminAddresses: @config.xxljob.adminAddresses@
appname: @config.xxljob.appname@
accessToken: @config.xxljob.accessToken@
logPath: @config.xxljob.logPath@
logRetentionDays: 30验证配置
启动应用后,在 XXL-JOB 管理中心的「执行器管理」中应该能看到注册的执行器:
| 执行器名称 | 执行器地址 | 在线状态 |
|---|---|---|
| widiazine-cloud-system | 192.168.1.100:9999 | 在线 |
文档版本: 1.0.0