初始化
commit
cc85ef62d8
|
@ -0,0 +1,46 @@
|
||||||
|
######################################################################
|
||||||
|
# Build Tools
|
||||||
|
|
||||||
|
.gradle
|
||||||
|
/build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# IDE
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### JRebel ###
|
||||||
|
rebel.xml
|
||||||
|
### NetBeans ###
|
||||||
|
nbproject/private/
|
||||||
|
build/*
|
||||||
|
nbbuild/
|
||||||
|
dist/
|
||||||
|
nbdist/
|
||||||
|
.nb-gradle/
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
# Others
|
||||||
|
*.log
|
||||||
|
*.xml.versionsBackup
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
!*/build/*.java
|
||||||
|
!*/build/*.html
|
||||||
|
!*/build/*.xml
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-common-xxl</artifactId>
|
||||||
|
|
||||||
|
<description>XllJob定时任务</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- MuYu Common Core-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- xxl-job-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.common.xxl;
|
||||||
|
|
||||||
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class XXLJobConfig {
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties) {
|
||||||
|
if (StringUtils.isEmpty(xxlJobProperties.getAdminAddresses())){
|
||||||
|
throw new RuntimeException("请在bootstrap.yml当中配置shared-configs项,xxl-job共享配置[application-xxl-config]");
|
||||||
|
}
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdminAddresses());
|
||||||
|
xxlJobSpringExecutor.setAppname(xxlJobProperties.getAppName());
|
||||||
|
xxlJobSpringExecutor.setIp(xxlJobProperties.getIp());
|
||||||
|
xxlJobSpringExecutor.setPort(xxlJobProperties.getPort());
|
||||||
|
xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAccessToken());
|
||||||
|
xxlJobSpringExecutor.setLogPath(xxlJobProperties.getLogPath());
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getLogRetentionDays());
|
||||||
|
log.info(">>>>>>>>>>> xxl-job config init success.");
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.muyu.common.xxl;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "xxl-job")
|
||||||
|
public class XxlJobProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调度中心部署根地址 [选填]:
|
||||||
|
* 如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";
|
||||||
|
* 为空则关闭自动注册;
|
||||||
|
*/
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器通讯TOKEN [选填]:
|
||||||
|
* 非空时启用;
|
||||||
|
*/
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器AppName [选填]:
|
||||||
|
* 执行器心跳注册分组依据;为空则关闭自动注册
|
||||||
|
*/
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器注册 [选填]:
|
||||||
|
* 优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。
|
||||||
|
* 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
|
||||||
|
*/
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器IP [选填]:
|
||||||
|
* 默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;
|
||||||
|
* 地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
|
||||||
|
*/
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器端口号 [选填]:
|
||||||
|
* 小于等于0则自动获取;默认端口为9999,
|
||||||
|
* 单机部署多个执行器时,注意要配置不同执行器端口;
|
||||||
|
*/
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器运行日志文件存储磁盘路径 [选填]:
|
||||||
|
* 需要对该路径拥有读写权限;为空则使用默认路径;
|
||||||
|
*/
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器日志文件保存天数 [选填]:
|
||||||
|
* 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
|
||||||
|
*/
|
||||||
|
private int logRetentionDays;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.muyu.common.xxl.demo;
|
||||||
|
|
||||||
|
import com.xxl.job.core.context.XxlJobHelper;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class XxlJobDemoService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参测试
|
||||||
|
*/
|
||||||
|
@XxlJob("xxl-job-demo-no-param")
|
||||||
|
public void xxlJobDemoNoParam(){
|
||||||
|
log.info("调度名称:[{}] - 无参", "xxl-job-demo-no-param");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有参测试
|
||||||
|
*/
|
||||||
|
@XxlJob("xxl-job-demo-one-param")
|
||||||
|
public void xxlJobDemoOneParam(){
|
||||||
|
String param = XxlJobHelper.getJobParam();
|
||||||
|
log.info("调度名称:[{}] - 参数:[{}]", "xxl-job-demo-one-param", param);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 分片测试
|
||||||
|
*/
|
||||||
|
@XxlJob("xxl-job-slice-demo")
|
||||||
|
public void xxlJobSliceDemo(){
|
||||||
|
int shardTotal = XxlJobHelper.getShardTotal();
|
||||||
|
int shardIndex = XxlJobHelper.getShardIndex();
|
||||||
|
String param = XxlJobHelper.getJobParam();
|
||||||
|
log.info("调度名称:[{}-[{}/{}(分片位置/分片总数)]] - 参数:[{}]", "xxl-job-slice-demo",shardIndex, shardTotal, param);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
com.muyu.common.xxl.XXLJobConfig
|
||||||
|
com.muyu.common.xxl.XxlJobProperties
|
||||||
|
com.muyu.common.xxl.demo.XxlJobDemoService
|
Loading…
Reference in New Issue