1. 增加 XXL-Job starter
2. 迁移 pay 服务的 Job 逻辑
This commit is contained in:
34
common/mall-spring-boot-starter-xxl-job/pom.xml
Normal file
34
common/mall-spring-boot-starter-xxl-job/pom.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>common</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mall-spring-boot-starter-xxl-job</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring 核心 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Job 相关 -->
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.iocoder.mall.xxljob.config;
|
||||
|
||||
import com.xxl.job.core.executor.XxlJobExecutor;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* XXL-Job 自动配置类
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(XxlJobSpringExecutor.class)
|
||||
@ConditionalOnProperty(prefix = "xxl.job", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
@EnableConfigurationProperties({XxlJobProperties.class})
|
||||
public class XxlJobAutoConfiguration {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(XxlJobAutoConfiguration.class);
|
||||
|
||||
private final XxlJobProperties properties;
|
||||
|
||||
public XxlJobAutoConfiguration(XxlJobProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public XxlJobExecutor xxlJobExecutor() {
|
||||
LOGGER.info("初始化 XXL-Job 执行器的配置");
|
||||
|
||||
// 参数校验
|
||||
XxlJobProperties.AdminProperties admin = this.properties.getAdmin();
|
||||
XxlJobProperties.ExecutorProperties executor = this.properties.getExecutor();
|
||||
Objects.requireNonNull(admin, "xxl job admin properties must not be null.");
|
||||
Objects.requireNonNull(executor, "xxl job executor properties must not be null.");
|
||||
|
||||
// 初始化执行器
|
||||
XxlJobExecutor xxlJobExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobExecutor.setIp(executor.getIp());
|
||||
xxlJobExecutor.setPort(executor.getPort());
|
||||
xxlJobExecutor.setAppname(executor.getAppName());
|
||||
xxlJobExecutor.setLogPath(executor.getLogPath());
|
||||
xxlJobExecutor.setLogRetentionDays(executor.getLogRetentionDays());
|
||||
xxlJobExecutor.setAdminAddresses(admin.getAddresses());
|
||||
xxlJobExecutor.setAccessToken(this.properties.getAccessToken());
|
||||
return xxlJobExecutor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package cn.iocoder.mall.xxljob.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* XXL-Job 配置类
|
||||
*/
|
||||
@ConfigurationProperties("xxl.job")
|
||||
public class XxlJobProperties {
|
||||
|
||||
/**
|
||||
* 是否开启,默认为 true 关闭
|
||||
*/
|
||||
private Boolean enabled = true;
|
||||
/**
|
||||
* 访问令牌
|
||||
*/
|
||||
private String accessToken;
|
||||
/**
|
||||
* 控制器配置
|
||||
*/
|
||||
private AdminProperties admin;
|
||||
/**
|
||||
* 执行器配置
|
||||
*/
|
||||
private ExecutorProperties executor;
|
||||
|
||||
public Boolean getEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(Boolean enabled) {
|
||||
if (enabled != null) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
if (accessToken != null && accessToken.trim().length() > 0) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
public AdminProperties getAdmin() {
|
||||
return admin;
|
||||
}
|
||||
|
||||
public void setAdmin(AdminProperties admin) {
|
||||
this.admin = admin;
|
||||
}
|
||||
|
||||
public ExecutorProperties getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public void setExecutor(ExecutorProperties executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* XXL-Job 调度器配置类
|
||||
*/
|
||||
public static class AdminProperties {
|
||||
|
||||
/**
|
||||
* 调度器地址
|
||||
*/
|
||||
private String addresses;
|
||||
|
||||
public String getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public void setAddresses(String addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AdminProperties{" +
|
||||
"addresses='" + addresses + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* XXL-Job 执行器配置类
|
||||
*/
|
||||
public static class ExecutorProperties {
|
||||
|
||||
/**
|
||||
* 默认端口
|
||||
*
|
||||
* 这里使用 -1 表示随机
|
||||
*/
|
||||
private static final Integer PORT_DEFAULT = -1;
|
||||
|
||||
/**
|
||||
* 默认日志保留天数
|
||||
*
|
||||
* 默认为 -1,不清理,永久保留
|
||||
*/
|
||||
private static final Integer LOG_RETENTION_DAYS_DEFAULT = -1;
|
||||
|
||||
/**
|
||||
* 应用名
|
||||
*/
|
||||
private String appName;
|
||||
/**
|
||||
* 执行器的 IP
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 执行器的 Port
|
||||
*/
|
||||
private Integer port = PORT_DEFAULT;
|
||||
/**
|
||||
* 日志地址
|
||||
*/
|
||||
private String logPath;
|
||||
/**
|
||||
* 日志保留天数
|
||||
*/
|
||||
private Integer logRetentionDays = LOG_RETENTION_DAYS_DEFAULT;
|
||||
|
||||
public String getAppName() {
|
||||
return appName;
|
||||
}
|
||||
|
||||
public void setAppName(String appName) {
|
||||
this.appName = appName;
|
||||
}
|
||||
|
||||
public String getLogPath() {
|
||||
return logPath;
|
||||
}
|
||||
|
||||
public void setLogPath(String logPath) {
|
||||
this.logPath = logPath;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Integer getLogRetentionDays() {
|
||||
return logRetentionDays;
|
||||
}
|
||||
|
||||
public void setLogRetentionDays(Integer logRetentionDays) {
|
||||
this.logRetentionDays = logRetentionDays;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.iocoder.mall.xxljob.config.XxlJobAutoConfiguration
|
||||
@@ -24,6 +24,7 @@
|
||||
<module>mall-spring-boot-starter-dubbo</module>
|
||||
<module>mall-spring-boot-starter-system-error-code</module>
|
||||
<module>mall-spring-boot-starter-rocketmq</module>
|
||||
<module>mall-spring-boot-starter-xxl-job</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
Reference in New Issue
Block a user