【优化】底层通讯超时时间支持自定义,默认3S;可参考 xxl-job-admin 和 samples 示例代码自行配置;

2.5.0
xuxueli 8 months ago
parent b20110ad31
commit 86d26c8793

@ -843,40 +843,45 @@ XXL-JOB是一个分布式任务调度平台其核心设计目标是开发迅
#### 步骤一:调度中心配置:
调度中心配置文件地址:
/xxl-job/xxl-job-admin/src/main/resources/application.properties
```
/xxl-job/xxl-job-admin/src/main/resources/application.properties
```
调度中心配置内容说明:
### 调度中心JDBC链接链接地址请保持和 2.1章节 所创建的调度数据库的地址一致
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root_pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### 报警邮箱
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
### 调度中心通讯TOKEN [选填]:非空时启用;
xxl.job.accessToken=
### 调度中心国际化配置 [必填] 默认为 "zh_CN"/中文简体, 可选范围为 "zh_CN"/中文简体, "zh_TC"/中文繁体 and "en"/英文;
xxl.job.i18n=zh_CN
## 调度线程池最大线程配置【必填】
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100
### 调度中心日志表数据保存天数 [必填]过期日志自动清理限制大于等于7时生效否则, 如-1关闭自动清理功能
xxl.job.logretentiondays=30
```
### 调度中心JDBC链接链接地址请保持和 2.1章节 所创建的调度数据库的地址一致
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root_pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
### 报警邮箱
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
### 调度中心通讯TOKEN [选填]:非空时启用;
xxl.job.accessToken=
### 调度中心通讯超时时间[选填]单位秒默认3s
xxl.job.timeout=3
### 调度中心国际化配置 [必填] 默认为 "zh_CN"/中文简体, 可选范围为 "zh_CN"/中文简体, "zh_TC"/中文繁体 and "en"/英文;
xxl.job.i18n=zh_CN
## 调度线程池最大线程配置【必填】
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100
### 调度中心日志表数据保存天数 [必填]过期日志自动清理限制大于等于7时生效否则, 如-1关闭自动清理功能
xxl.job.logretentiondays=30
```
#### 步骤二:部署项目:
@ -931,29 +936,35 @@ docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_jo
#### 步骤二:执行器配置
执行器配置,配置文件地址:
/xxl-job/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/application.properties
```
/xxl-job/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/application.properties
```
执行器配置,配置内容说明:
### 调度中心部署根地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### 执行器通讯TOKEN [选填]:非空时启用;
xxl.job.accessToken=
### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
xxl.job.executor.appname=xxl-job-executor-sample
### 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
xxl.job.executor.address=
### 执行器IP [选填]默认为空表示自动获取IP多网卡时可手动设置指定IP该IP不会绑定Host仅作为通讯实用地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"
xxl.job.executor.ip=
### 执行器端口号 [选填]小于等于0则自动获取默认端口为9999单机部署多个执行器时注意要配置不同执行器端口
xxl.job.executor.port=9999
### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
### 执行器日志文件保存天数 [选填] 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
xxl.job.executor.logretentiondays=30
```
### 调度中心部署根地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### 调度中心通讯TOKEN [选填]:非空时启用;
xxl.job.admin.accessToken=default_token
### 调度中心通讯超时时间[选填]单位秒默认3s
xxl.job.admin.timeout=3
### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
xxl.job.executor.appname=xxl-job-executor-sample
### 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
xxl.job.executor.address=
### 执行器IP [选填]默认为空表示自动获取IP多网卡时可手动设置指定IP该IP不会绑定Host仅作为通讯实用地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"
xxl.job.executor.ip=
### 执行器端口号 [选填]小于等于0则自动获取默认端口为9999单机部署多个执行器时注意要配置不同执行器端口
xxl.job.executor.port=9999
### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
### 执行器日志文件保存天数 [选填] 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
xxl.job.executor.logretentiondays=30
```
#### 步骤三:执行器组件配置
@ -2402,14 +2413,15 @@ public void execute() {
### 7.36 版本 v2.5.0 Release Notes[规划中]
- 1、【优化】框架基础守护线程异常处理逻辑优化避免极端情况下因Error导致调度终止问题
- 2、【优化】部分系统日志优化,提升可读性
- 2、【优化】底层通讯超时时间支持自定义默认3S可参考 xxl-job-admin 和 samples 示例代码自行配置
- 3、【重构】调度线程任务信息更新逻辑优化避免极端情况下已关闭任务被启动问题
- 5、【重构】执行器注册逻辑重构降低多调度中心地址时并发注册问题注册表“xxl_job_registry”新增唯一索引避免冗余注册信息存储
- 4、【重构】执行器注册逻辑重构降低多调度中心地址时并发注册问题注册表“xxl_job_registry”新增唯一索引避免冗余注册信息存储
- 5、【优化】部分系统日志优化提升可读性
- 6、【优化】合并PR-3616代码结构注释优化
- 7、【优化】合并PR-3619避免调度过程中任务停止边界情况处理逻辑
- 8、【优化】合并PR-3605避免子任务是任务本身导致死循环
- 9、【修复】合并PR-3585修复全局密码长度不一致问题
- 10、【优化】合并PR-3518列别名反引号包裹,提升跨数据迁移兼容性;
- 10、【优化】合并PR-3518SQL列别名反引号包裹,提升跨数据迁移兼容性;
- 11、【优化】合并PR-3518、PR-3400日志表索引优化提升大日志量情况下日志查询及清理速度
- 12、[规划中]登陆态Token声称逻辑优化混淆登陆时间属性降低token泄漏风险
- 13、[规划中]升级springboot3.x解决2.x老版本漏洞类问题。注意springboot3.x依赖jdk17

@ -55,6 +55,9 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean {
@Value("${xxl.job.accessToken}")
private String accessToken;
@Value("${xxl.job.timeout}")
private int timeout;
@Value("${spring.mail.from}")
private String emailFrom;
@ -98,6 +101,10 @@ public class XxlJobAdminConfig implements InitializingBean, DisposableBean {
return accessToken;
}
public int getTimeout() {
return timeout;
}
public String getEmailFrom() {
return emailFrom;
}

@ -92,7 +92,9 @@ public class XxlJobScheduler {
}
// set-cache
executorBiz = new ExecutorBizClient(address, XxlJobAdminConfig.getAdminConfig().getAccessToken());
executorBiz = new ExecutorBizClient(address,
XxlJobAdminConfig.getAdminConfig().getAccessToken(),
XxlJobAdminConfig.getAdminConfig().getTimeout());
executorBizRepository.put(address, executorBiz);
return executorBiz;

@ -3,13 +3,13 @@ server.port=8080
server.servlet.context-path=/xxl-job-admin
### actuator
management.server.servlet.context-path=/actuator
management.server.base-path=/actuator
management.health.mail.enabled=false
### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
spring.web.resources.static-locations=classpath:/static/
### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
@ -21,13 +21,6 @@ spring.freemarker.settings.new_builtin_class_resolver=safer
### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root_pwd
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
### datasource-pool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
@ -41,6 +34,12 @@ spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.validation-timeout=1000
### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root_pwd
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
### xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
@ -55,6 +54,9 @@ spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFact
### xxl-job, access token
xxl.job.accessToken=default_token
### xxl-job, access token
xxl.job.timeout=3
### xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
xxl.job.i18n=zh_CN

@ -24,11 +24,12 @@ public class AdminBizTest {
// admin-client
private static String addressUrl = "http://127.0.0.1:8080/xxl-job-admin/";
private static String accessToken = null;
private static int timeoutSecond = 3;
@Test
public void callback() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken, timeoutSecond);
HandleCallbackParam param = new HandleCallbackParam();
param.setLogId(1);
@ -48,7 +49,7 @@ public class AdminBizTest {
*/
@Test
public void registry() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken, timeoutSecond);
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
ReturnT<String> returnT = adminBiz.registry(registryParam);
@ -63,7 +64,7 @@ public class AdminBizTest {
*/
@Test
public void registryRemove() throws Exception {
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken);
AdminBiz adminBiz = new AdminBizClient(addressUrl, accessToken, timeoutSecond);
RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
ReturnT<String> returnT = adminBiz.registryRemove(registryParam);

@ -18,10 +18,11 @@ public class ExecutorBizTest {
// admin-client
private static String addressUrl = "http://127.0.0.1:9999/";
private static String accessToken = null;
private static int timeout = 3;
@Test
public void beat() throws Exception {
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken, timeout);
// Act
final ReturnT<String> retval = executorBiz.beat();
@ -34,7 +35,7 @@ public class ExecutorBizTest {
@Test
public void idleBeat(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken, timeout);
final int jobId = 0;
@ -50,7 +51,7 @@ public class ExecutorBizTest {
@Test
public void run(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken, timeout);
// trigger data
final TriggerParam triggerParam = new TriggerParam();
@ -73,7 +74,7 @@ public class ExecutorBizTest {
@Test
public void kill(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken, timeout);
final int jobId = 0;
@ -89,7 +90,7 @@ public class ExecutorBizTest {
@Test
public void log(){
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken);
ExecutorBiz executorBiz = new ExecutorBizClient(addressUrl, accessToken, timeout);
final long logDateTim = 0L;
final long logId = 0;

@ -17,19 +17,23 @@ public class AdminBizClient implements AdminBiz {
public AdminBizClient() {
}
public AdminBizClient(String addressUrl, String accessToken) {
public AdminBizClient(String addressUrl, String accessToken, int timeout) {
this.addressUrl = addressUrl;
this.accessToken = accessToken;
this.timeout = timeout;
// valid
if (!this.addressUrl.endsWith("/")) {
this.addressUrl = this.addressUrl + "/";
}
if (!(this.timeout >=1 && this.timeout <= 10)) {
this.timeout = 3;
}
}
private String addressUrl ;
private String accessToken;
private int timeout = 3;
private int timeout;
@Override

@ -13,19 +13,23 @@ public class ExecutorBizClient implements ExecutorBiz {
public ExecutorBizClient() {
}
public ExecutorBizClient(String addressUrl, String accessToken) {
public ExecutorBizClient(String addressUrl, String accessToken, int timeout) {
this.addressUrl = addressUrl;
this.accessToken = accessToken;
this.timeout = timeout;
// valid
if (!this.addressUrl.endsWith("/")) {
this.addressUrl = this.addressUrl + "/";
}
if (!(this.timeout >=1 && this.timeout <= 10)) {
this.timeout = 3;
}
}
private String addressUrl ;
private String accessToken;
private int timeout = 3;
private int timeout;
@Override

@ -31,6 +31,7 @@ public class XxlJobExecutor {
// ---------------------- param ----------------------
private String adminAddresses;
private String accessToken;
private int timeout;
private String appname;
private String address;
private String ip;
@ -44,6 +45,9 @@ public class XxlJobExecutor {
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public void setAppname(String appname) {
this.appname = appname;
}
@ -71,7 +75,7 @@ public class XxlJobExecutor {
XxlJobFileAppender.initLogPath(logPath);
// init invoker, admin-client
initAdminBizList(adminAddresses, accessToken);
initAdminBizList(adminAddresses, accessToken, timeout);
// init JobLogFileCleanThread
@ -117,12 +121,12 @@ public class XxlJobExecutor {
// ---------------------- admin-client (rpc invoker) ----------------------
private static List<AdminBiz> adminBizList;
private void initAdminBizList(String adminAddresses, String accessToken) throws Exception {
private void initAdminBizList(String adminAddresses, String accessToken, int timeout) throws Exception {
if (adminAddresses!=null && adminAddresses.trim().length()>0) {
for (String address: adminAddresses.trim().split(",")) {
if (address!=null && address.trim().length()>0) {
AdminBiz adminBiz = new AdminBizClient(address.trim(), accessToken);
AdminBiz adminBiz = new AdminBizClient(address.trim(), accessToken, timeout);
if (adminBizList == null) {
adminBizList = new ArrayList<AdminBiz>();

@ -60,7 +60,7 @@ public class XxlJobRemotingUtil {
*
* @param url
* @param accessToken
* @param timeout
* @param timeout by second
* @param requestObj
* @param returnTargClassOfT
* @return
@ -86,7 +86,7 @@ public class XxlJobRemotingUtil {
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setReadTimeout(timeout * 1000);
connection.setConnectTimeout(3 * 1000);
connection.setConnectTimeout(timeout * 1000);
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");

@ -36,7 +36,8 @@ public class FrameLessXxlJobConfig {
// init executor
xxlJobExecutor = new XxlJobSimpleExecutor();
xxlJobExecutor.setAdminAddresses(xxlJobProp.getProperty("xxl.job.admin.addresses"));
xxlJobExecutor.setAccessToken(xxlJobProp.getProperty("xxl.job.accessToken"));
xxlJobExecutor.setAccessToken(xxlJobProp.getProperty("xxl.job.admin.accessToken"));
xxlJobExecutor.setTimeout(Integer.valueOf(xxlJobProp.getProperty("xxl.job.admin.timeout")));
xxlJobExecutor.setAppname(xxlJobProp.getProperty("xxl.job.executor.appname"));
xxlJobExecutor.setAddress(xxlJobProp.getProperty("xxl.job.executor.address"));
xxlJobExecutor.setIp(xxlJobProp.getProperty("xxl.job.executor.ip"));

@ -1,8 +1,9 @@
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### xxl-job, access token
xxl.job.accessToken=default_token
### xxl-job access-token
xxl.job.admin.accessToken=default_token
### xxl-job timeout by second, default 3s
xxl.job.admin.timeout=3
### xxl-job executor appname
xxl.job.executor.appname=xxl-job-executor-sample

@ -19,9 +19,12 @@ public class XxlJobConfig {
@Value("${xxl.job.admin.addresses}")
private String adminAddresses;
@Value("${xxl.job.accessToken}")
@Value("${xxl.job.admin.accessToken}")
private String accessToken;
@Value("${xxl.job.admin.timeout}")
private int timeout;
@Value("${xxl.job.executor.appname}")
private String appname;
@ -51,6 +54,7 @@ public class XxlJobConfig {
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setTimeout(timeout);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);

@ -9,9 +9,10 @@ logging.config=classpath:logback.xml
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### xxl-job, access token
xxl.job.accessToken=default_token
xxl.job.admin.accessToken=default_token
### xxl-job timeout by second, default 3s
xxl.job.admin.timeout=3
### xxl-job executor appname
xxl.job.executor.appname=xxl-job-executor-sample

Loading…
Cancel
Save