初始化仓库
This commit is contained in:
19
xtools-boot-job/pom.xml
Normal file
19
xtools-boot-job/pom.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>xtools-boot-job</artifactId>
|
||||
|
||||
<!-- 子模块 -->
|
||||
<modules>
|
||||
<module>xtools-boot-job-xxl</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
41
xtools-boot-job/xtools-boot-job-xxl/README.md
Normal file
41
xtools-boot-job/xtools-boot-job-xxl/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# xxl-job使用
|
||||
|
||||
## 官网地址
|
||||
|
||||
[xxl-job官网](https://www.xuxueli.com/xxl-job)
|
||||
|
||||
## 操作说明
|
||||
|
||||
> 1.先安装xxl-job-admin
|
||||
> 2.配置application-boot-xxl-job.yaml文件,可以参考application-boot-xxl-job-demo.yaml
|
||||
> 3.运行项目,即可在admin配置定时任务了
|
||||
|
||||
## docker命令
|
||||
|
||||
```sh
|
||||
# docker命令启动
|
||||
docker run -d \
|
||||
-e PARAMS=" \
|
||||
--spring.datasource.url=jdbc:mysql://devmysql.xujun.org:11010/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai \
|
||||
--spring.datasource.username=demo \
|
||||
--spring.datasource.password=demo321 \
|
||||
--xxl.job.accessToken=xtools-app-xxl-job \
|
||||
" \
|
||||
-p 26000:8080 \
|
||||
-v /data1/xxl-job-admin/applogs:/data/applogs \
|
||||
--name xxl-job-admin \
|
||||
registry.cn-hangzhou.aliyuncs.com/xujun-public/xxl-job-admin:3.3.2
|
||||
```
|
||||
|
||||
## docker-compose
|
||||
|
||||
> 参考docker-compose目录
|
||||
|
||||
## 访问
|
||||
|
||||
```sh
|
||||
# 访问地址
|
||||
http://[ip]:[port]/xxl-job-admin
|
||||
# 账号/密码
|
||||
admin/123456
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
services:
|
||||
xxl-job-admin:
|
||||
container_name: xxl-job-admin
|
||||
image: registry.cn-hangzhou.aliyuncs.com/xujun-public/xxl-job-admin:3.3.2
|
||||
pull_policy: always
|
||||
ports:
|
||||
- "26000:8080"
|
||||
volumes:
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
- "/data1/xxl-job-admin/applogs:/data/applogs"
|
||||
env_file:
|
||||
- env/container.env
|
||||
restart: always
|
||||
networks:
|
||||
- xxl_job_net
|
||||
|
||||
networks:
|
||||
xxl_job_net:
|
||||
name: xxl_job_net
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.201.0.0/16
|
||||
@@ -0,0 +1,2 @@
|
||||
# xxl-job-admin配置
|
||||
PARAMS=--spring.datasource.url=jdbc:mysql://devmysql.xujun.org:11010/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai --spring.datasource.username=demo --spring.datasource.password=demo321 --xxl.job.accessToken=xtools-app-xxl-job
|
||||
36
xtools-boot-job/xtools-boot-job-xxl/pom.xml
Normal file
36
xtools-boot-job/xtools-boot-job-xxl/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-job</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<artifactId>xtools-boot-job-xxl</artifactId>
|
||||
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- xtools-boot begin -->
|
||||
<!-- xtools-boot-core -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-core</artifactId>
|
||||
</dependency>
|
||||
<!-- xtools-boot end -->
|
||||
|
||||
<!-- xxl-job -->
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- spring-boot -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package xtools.boot.job.xxl;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import xtools.boot.core.utils.ModuleLoadUtils;
|
||||
import xtools.boot.job.xxl.selector.BootXxlJobImportSelector;
|
||||
|
||||
/**
|
||||
* <p>Title : BootXxlJobConfiguration</p>
|
||||
* <p>Description : BootXxlJobConfiguration</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
@Import(BootXxlJobImportSelector.class)
|
||||
public class BootXxlJobConfiguration {
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public BootXxlJobConfiguration() {
|
||||
ModuleLoadUtils.loadSuccess(BootXxlJobConfiguration.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package xtools.boot.job.xxl.config;
|
||||
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import xtools.core.StringUtils;
|
||||
|
||||
/**
|
||||
* <p>Title : XxlJobConfig</p>
|
||||
* <p>Description : XxlJobConfig</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/3/10 14:06
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class XxlJobConfig {
|
||||
|
||||
/**
|
||||
* 调度中心部署根地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔.执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
|
||||
*/
|
||||
@Value("${xxl.job.admin.addresses}")
|
||||
private String adminAddresses;
|
||||
|
||||
/**
|
||||
* 调度中心通讯TOKEN [选填]:非空时启用;
|
||||
*/
|
||||
@Value("${xxl.job.admin.accessToken}")
|
||||
private String accessToken;
|
||||
|
||||
/**
|
||||
* 调度中心通讯超时时间[选填],单位秒;默认3s;
|
||||
*/
|
||||
@Value("${xxl.job.admin.timeout}")
|
||||
private int timeout;
|
||||
|
||||
/**
|
||||
* 执行器启用开关 [选填]:默认开启,关闭时不进行执行器初始化;
|
||||
*/
|
||||
@Getter
|
||||
@Value("${xxl.job.executor.enabled:false}")
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
|
||||
*/
|
||||
@Value("${xxl.job.executor.appName}")
|
||||
private String appName;
|
||||
|
||||
/**
|
||||
* 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址.从而更灵活支持容器类型执行器动态IP和动态映射端口问题.
|
||||
*/
|
||||
@Value("${xxl.job.executor.address}")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯使用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
|
||||
*/
|
||||
@Value("${xxl.job.executor.ip}")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
|
||||
*/
|
||||
@Value("${xxl.job.executor.port}")
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
|
||||
*/
|
||||
@Value("${xxl.job.executor.logPath}")
|
||||
private String logPath;
|
||||
|
||||
/**
|
||||
* 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
|
||||
*/
|
||||
@Value("${xxl.job.executor.logRetentionDays}")
|
||||
private int logRetentionDays;
|
||||
|
||||
/**
|
||||
* 任务扫描排除路径 [选填] :任务扫描时忽略指定包路径下的Bean;支持配置包路径前缀,多个逗号分隔;
|
||||
*/
|
||||
@Value("${xxl.job.executor.excludedPackage}")
|
||||
private String excludedPackage;
|
||||
|
||||
/**
|
||||
* xxl-job 执行器
|
||||
*
|
||||
* @return xxl-job 执行器
|
||||
*/
|
||||
@Bean
|
||||
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||
xxlJobSpringExecutor.setTimeout(timeout);
|
||||
xxlJobSpringExecutor.setEnabled(enabled);
|
||||
xxlJobSpringExecutor.setAppname(appName);
|
||||
if (StringUtils.isNotBlank(address)) {
|
||||
xxlJobSpringExecutor.setAddress(address);
|
||||
}
|
||||
if (StringUtils.isNotBlank(ip)) {
|
||||
xxlJobSpringExecutor.setIp(ip);
|
||||
}
|
||||
if (port > 0) {
|
||||
xxlJobSpringExecutor.setPort(port);
|
||||
}
|
||||
if (StringUtils.isNotBlank(logPath)) {
|
||||
xxlJobSpringExecutor.setLogPath(logPath);
|
||||
}
|
||||
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||
if (StringUtils.isNotBlank(excludedPackage)) {
|
||||
xxlJobSpringExecutor.setExcludedPackage(excludedPackage);
|
||||
}
|
||||
return xxlJobSpringExecutor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package xtools.boot.job.xxl.init;
|
||||
|
||||
import com.xxl.job.core.executor.XxlJobExecutor;
|
||||
import com.xxl.job.core.handler.IJobHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xtools.base.config.BaseParams;
|
||||
import xtools.boot.core.interfaces.JobInterface;
|
||||
import xtools.boot.core.utils.SpringContextUtils;
|
||||
import xtools.boot.job.xxl.config.XxlJobConfig;
|
||||
import xtools.core.CollectionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>Title : InitIp</p>
|
||||
* <p>Description : InitIp</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/2/16 10:21
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(BaseParams.CP_NUM90)
|
||||
public class InitXxlJob implements ApplicationRunner, BaseParams {
|
||||
|
||||
private final XxlJobConfig xxlJobConfig;
|
||||
|
||||
@Override
|
||||
public void run(@NonNull ApplicationArguments args) {
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private void init() {
|
||||
Boolean enabled = xxlJobConfig.getEnabled();
|
||||
if (Objects.isNull(enabled) || !enabled) {
|
||||
log.info("xxl-job未启用");
|
||||
return;
|
||||
}
|
||||
Collection<JobInterface> beanList = SpringContextUtils.getBeanList(JobInterface.class);
|
||||
if (CollectionUtils.isEmpty(beanList)) {
|
||||
log.info("没有需要执行xxl-job的任务");
|
||||
return;
|
||||
}
|
||||
beanList.forEach(item -> {
|
||||
try {
|
||||
String name = item.getClass().getSimpleName();
|
||||
name = Character.toLowerCase(name.charAt(CP_NUM0)) + name.substring(CP_NUM1);
|
||||
registerXxlJob(name, item);
|
||||
log.info("注册xxl-job任务成功:{}", name);
|
||||
} catch (Exception e) {
|
||||
log.error("注册xxl-job任务异常", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册任务
|
||||
*
|
||||
* @param name 任务名称
|
||||
* @param job 任务
|
||||
*/
|
||||
private void registerXxlJob(String name, JobInterface job) {
|
||||
IJobHandler handler = new IJobHandler() {
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
job.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
job.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
job.destroy();
|
||||
}
|
||||
};
|
||||
// 注册到XXL-JOB
|
||||
XxlJobExecutor.registryJobHandler(name, handler);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xtools.boot.job.xxl.selector;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* <p>Title : BootXxlJobImportSelector</p>
|
||||
* <p>Description : BootXxlJobImportSelector</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
public class BootXxlJobImportSelector implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
/**
|
||||
* 根据给定的注释元数据,根据需要注册bean
|
||||
*
|
||||
* @param importingClassMetadata AnnotationMetadata
|
||||
* @param registry BeanDefinitionRegistry
|
||||
*/
|
||||
@Override
|
||||
public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMetadata, @NonNull BeanDefinitionRegistry registry) {
|
||||
// 构建扫描对象
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry, true);
|
||||
// 扫描包下路径
|
||||
scanner.scan("xtools.boot.job.xxl");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
xtools.boot.job.xxl.BootXxlJobConfiguration
|
||||
@@ -0,0 +1,26 @@
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
# 调度中心部署根地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔.执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
|
||||
addresses: http://10.1.0.12:8080/xxl-job-admin
|
||||
# 调度中心通讯TOKEN [选填]:非空时启用;
|
||||
accessToken: xtools-app-xxl-job
|
||||
# 调度中心通讯超时时间[选填],单位秒;默认3s;
|
||||
timeout: 3
|
||||
executor:
|
||||
# 执行器启用开关 [选填]:默认开启,关闭时不进行执行器初始化;
|
||||
enabled: true
|
||||
# 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
|
||||
appName: xtools-cloud
|
||||
# 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址.从而更灵活支持容器类型执行器动态IP和动态映射端口问题.
|
||||
address: ""
|
||||
# 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯使用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
|
||||
ip: ""
|
||||
# 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
|
||||
port: 9999
|
||||
# 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
|
||||
logPath: /Users/xujun/Downloads/xtools
|
||||
# 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
|
||||
logRetentionDays: 30
|
||||
# 任务扫描排除路径 [选填] :任务扫描时忽略指定包路径下的Bean;支持配置包路径前缀,多个逗号分隔;
|
||||
excludedPackage: ""
|
||||
Reference in New Issue
Block a user