Initial commit

This commit is contained in:
Eric
2026-01-16 18:51:16 +08:00
commit 98c057de11
280 changed files with 16665 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.lingniu.framework</groupId>
<artifactId>lingniu-framework-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../../lingniu-framework-dependencies/pom.xml</relativePath>
</parent>
<artifactId>lingniu-framework-plugin-xxljob</artifactId>
<name>${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>cn.lingniu.framework</groupId>
<artifactId>lingniu-framework-plugin-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,64 @@
package cn.lingniu.framework.plugin.xxljob.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties(XxlJobConfig.PRE_FIX)
public class XxlJobConfig {
public final static String PRE_FIX = "framework.lingniu.xxljob";
/**
* xxl job admin properties.
*/
private AdminProperties admin = new AdminProperties();
/**
* xxl job executor properties.
*/
private ExecutorProperties executor = new ExecutorProperties();
/**
* xxl-job admin properties.
*/
@Data
static public class AdminProperties {
/**
* xxl job admin address.
*/
private String adminAddresses = "http://xxx:8080/xxl-job-admin";
/**
* xxl job admin registry access token.
*/
private String accessToken;
}
/**
* xxl-job executor properties.
*/
@Data
static public class ExecutorProperties {
/**
* xxl job registry name. [等于 spring.application.name] ApplicationNameContext.getApplicationName()
*/
private String appName = "xxl-job-executor";
/**
* xxl job registry ip.
*/
private String ip;
/**
* xxl job registry port.
*/
private Integer port = 9999;
/**
* xxl job log files path. todo 注意权限问题
*/
private String logPath = "logs/applogs/xxl-job/jobhandler";
/**
* xxl job log files retention days.
*/
private Integer logRetentionDays = 7;
}
}

View File

@@ -0,0 +1,41 @@
package cn.lingniu.framework.plugin.xxljob.init;
import cn.lingniu.framework.plugin.core.context.ApplicationNameContext;
import cn.lingniu.framework.plugin.util.json.JsonUtil;
import cn.lingniu.framework.plugin.xxljob.config.XxlJobConfig;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@Slf4j
@EnableConfigurationProperties({XxlJobConfig.class})
public class XxlJobAutoConfiguration {
@Bean(initMethod = "start", destroyMethod = "destroy")
public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobConfig prop) {
validateXxlJobConfig(prop);
XxlJobSpringExecutor executor = new XxlJobSpringExecutor();
executor.setAdminAddresses(prop.getAdmin().getAdminAddresses());
executor.setAccessToken(prop.getAdmin().getAccessToken());
executor.setPort(prop.getExecutor().getPort());
executor.setLogRetentionDays(prop.getExecutor().getLogRetentionDays());
executor.setLogPath(prop.getExecutor().getLogPath());
executor.setIp(prop.getExecutor().getIp());
executor.setAppname(ApplicationNameContext.getApplicationName());
log.info("XxlJob configuration initialized: {}", JsonUtil.bean2Json(prop));
return executor;
}
private void validateXxlJobConfig(XxlJobConfig prop) {
if (prop.getAdmin() == null || prop.getExecutor() == null) {
throw new IllegalArgumentException("XxlJob configuration cannot be null");
}
}
}

View File

@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.lingniu.framework.plugin.xxljob.init.XxlJobAutoConfiguration

View File

@@ -0,0 +1,43 @@
# 【重要】xxl-job服务搭建、和详细demo使用教程---参考官网
## 概述 (Overview)
1. 定位: 基于 xxljob 封装的分布式定时任务开发工具
2. 核心能力:
* 分布式任务调度:基于 XXL-JOB 实现任务的分布式执行和分片处理。
* 动态调度:支持任务的动态添加、修改和删除,无需重启服务。
* 故障转移:自动检测任务执行失败并重新分配,确保任务高可用。
* 监控与管理:提供任务执行日志、状态监控和告警功能。
* 插件化集成:通过插件机制与主框架无缝对接,支持动态加载和卸载。
3. 适用场景:
* 定时任务:如报表生成、数据清理等周期性任务。
* 分布式计算:需要分片处理大量数据的场景。
* 高可用需求:确保任务在节点故障时自动恢复。
* 动态调整:需要灵活调整任务执行策略的场景。
## 如何配置--参考XxlJobConfig
```yaml
framework:
lingniu:
# XXL-JOB 配置
xxljob:
# 调度中心配置
admin:
# 调度中心部署根地址(多个地址用逗号分隔,为空则关闭自动注册)
adminAddresses: "http://xxx:8099/xxl-job-admin"
# 调度中心通讯TOKEN非空时启用
accessToken: "default_token"
# 执行器配置
executor:
# 执行器IP默认为空表示自动获取IP
ip: ""
# 执行器端口号小于等于0则自动获取默认9999
port: 9999
# 执行器日志文件保存天数大于等于3时生效-1表示关闭自动清理默认7天
logRetentionDays: 7
# 执行器运行日志文件存储磁盘路径(需对该路径拥有读写权限,为空则使用默认路径)
logPath: logs/applogs/xxl-job/jobhandler
```