Commit cbb7ac27 by haozi

加xxl-job starter

parent 9c075380
......@@ -25,6 +25,7 @@
<module>matrix-protocol</module>
<module>matrix-datasource</module>
<module>rocketmq-starter</module>
<module>xxl-job-starter</module>
</modules>
......@@ -145,7 +146,11 @@
<artifactId>matrix-protocol-web-starter</artifactId>
<version>1.2.12.RELEASE</version>
</dependency>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>xxl-job-starter</artifactId>
<version>1.2.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
......@@ -212,6 +217,13 @@
<artifactId>apollo-client</artifactId>
<version>1.4.0</version>
</dependency>
<!--xxl-job-->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
......
<?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>matrix</artifactId>
<groupId>com.secoo.mall</groupId>
<version>1.2.12.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>xxl-job-starter</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.secoo.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.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.File;
/**
* xxl-job 自动注入初始化
*
* @author zhanghao
* @date 2020-03-1010:02
*/
@Configuration
@ConditionalOnClass(XxlJobSpringExecutor.class)
@ConditionalOnProperty(prefix = "xxl.job", name = "enabled", havingValue = "true")
public class XxlJobAutoConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(XxlJobAutoConfiguration.class);
/**
* 以下必填
*/
@Value("${spring.application.name}")
private String appName;
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
/**
* 以下选填
*/
@Value("${xxl.job.executor.ip:}")
private String ip;
@Value("${xxl.job.executor.port:-1}")
private int port;
@Value("${xxl.job.accessToken:}")
private String accessToken;
@Value("${log.path:/data/logs}")
private String logPath;
@Value("${log.max_history:7}")
private int logRetentionDays;
@Bean
@ConditionalOnMissingBean
public XxlJobExecutor xxlJobExecutor() {
LOGGER.info(">>>>>>>>>>> xxl-job config init.");
XxlJobExecutor xxlJobExecutor = new XxlJobSpringExecutor();
//执行器AppName[选填],为空则关闭自动注册
xxlJobExecutor.setAppName(appName);
//执行器注册中心地址[选填],为空则关闭自动注册
xxlJobExecutor.setAdminAddresses(adminAddresses);
//执行器IP[选填],为空则自动获取
xxlJobExecutor.setIp(ip);
//执行器端口号[选填],小于等于0则自动获取,default 9999
xxlJobExecutor.setPort(port);
//访问令牌[选填],非空则进行匹配校验
xxlJobExecutor.setAccessToken(accessToken);
//执行器日志路径[选填],为空则使用默认路径
if (!logPath.contains(appName)) {
//目录加应用名
logPath += File.separator + appName;
}
xxlJobExecutor.setLogPath(logPath);
//日志保存天数[选填],值大于3时生效
xxlJobExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobExecutor;
}
}
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.secoo.mall.xxljob.config.XxlJobAutoConfiguration
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment