跨平台:除了提供Java、Python、PHP等十来种任务模式之外,新增提供基于HTTP的任务模式;

v1.9.2
xuxueli 6 years ago
parent d6dc40b49e
commit a1755156e2

@ -955,6 +955,11 @@ echo "分片总数 total = $3"
需要注意的是任务超时中断时与任务终止机制可查看“4.8 终止运行中的任务”)类似,也是通过 "interrupt" 中断任务,因此业务代码需要将 "InterruptedException" 外抛,否则功能不可用。 需要注意的是任务超时中断时与任务终止机制可查看“4.8 终止运行中的任务”)类似,也是通过 "interrupt" 中断任务,因此业务代码需要将 "InterruptedException" 外抛,否则功能不可用。
### 5.17 跨平台 & 跨语言
跨平台、跨语言主要体现在以下两个方面:
- 1、提供Java、Python、PHP……等十来种任务模式可参考章节 “5.5 任务 "运行模式" ”;理论上可扩展任意语言任务模式;
- 2、提供基于HTTP的任务HandlerBean任务JobHandler="httpJobHandler"业务方只需要提供HTTP链接即可不限制语言、平台
## 六、版本更新日志 ## 六、版本更新日志
### 6.1 版本 V1.1.x新特性[2015-12-05] ### 6.1 版本 V1.1.x新特性[2015-12-05]
@ -1244,7 +1249,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 28、新增任务运行模式 "GLUE模式(PowerShell) "支持PowerShell脚本任务 - 28、新增任务运行模式 "GLUE模式(PowerShell) "支持PowerShell脚本任务
- 29、GLUE脚本文件自动清理功能及时清理过期脚本文件 - 29、GLUE脚本文件自动清理功能及时清理过期脚本文件
- 30、执行器注册方式切换优化切换自动注册时主动同步在线机器避免执行器为空的问题 - 30、执行器注册方式切换优化切换自动注册时主动同步在线机器避免执行器为空的问题
- 31、【迭代中】分片任务失败重试优化仅重试当前失败的分片 - 31、跨平台除了提供Java、Python、PHP等十来种任务模式之外新增提供基于HTTP的任务模式
- 32、【迭代中】分片任务失败重试优化仅重试当前失败的分片
### TODO LIST ### TODO LIST

@ -5,6 +5,7 @@ import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit; import com.jfinal.kit.PropKit;
import com.xuxueli.executor.sample.jfinal.controller.IndexController; import com.xuxueli.executor.sample.jfinal.controller.IndexController;
import com.xuxueli.executor.sample.jfinal.jobhandler.DemoJobHandler; import com.xuxueli.executor.sample.jfinal.jobhandler.DemoJobHandler;
import com.xuxueli.executor.sample.jfinal.jobhandler.HttpJobHandler;
import com.xuxueli.executor.sample.jfinal.jobhandler.ShardingJobHandler; import com.xuxueli.executor.sample.jfinal.jobhandler.ShardingJobHandler;
import com.xxl.job.core.executor.XxlJobExecutor; import com.xxl.job.core.executor.XxlJobExecutor;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -23,6 +24,7 @@ public class JFinalCoreConfig extends JFinalConfig {
// registry jobhandler // registry jobhandler
XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler()); XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler());
XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler()); XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler());
XxlJobExecutor.registJobHandler("httpJobHandler", new HttpJobHandler());
// load executor prop // load executor prop
Prop xxlJobProp = PropKit.use("xxl-job-executor.properties"); Prop xxlJobProp = PropKit.use("xxl-job-executor.properties");

@ -0,0 +1,77 @@
package com.xuxueli.executor.sample.jfinal.jobhandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* Http
*
* @author xuxueli 2018-09-16 03:48:34
*/
public class HttpJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
// valid
if (param==null || param.trim().length()==0) {
XxlJobLogger.log("URL Empty");
return FAIL;
}
// httpGet config
HttpGet httpGet = new HttpGet(param);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpGet.setConfig(requestConfig);
CloseableHttpClient httpClient = null;
try{
httpClient = HttpClients.custom().disableAutomaticRetries().build();
// parse response
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() != 200) {
XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatusLine().getStatusCode());
return FAIL;
}
if (null == entity) {
XxlJobLogger.log("Http Entity Empty.");
return FAIL;
}
String responseMsg = EntityUtils.toString(entity, "UTF-8");
XxlJobLogger.log(responseMsg);
EntityUtils.consume(entity);
return SUCCESS;
} catch (Exception e) {
XxlJobLogger.log(e);
return FAIL;
} finally{
if (httpGet!=null) {
httpGet.releaseConnection();
}
if (httpClient!=null) {
try {
httpClient.close();
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
}
}
}

@ -5,7 +5,6 @@ import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.log.XxlJobLogger; import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil; import com.xxl.job.core.util.ShardingUtil;
/** /**
* 广 * 广
* *

@ -0,0 +1,78 @@
package com.xuxueli.executor.sample.nutz.jobhandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.nutz.ioc.loader.annotation.IocBean;
import java.io.IOException;
/**
* Http
*
* @author xuxueli 2018-09-16 03:48:34
*/
@JobHandler(value="httpJobHandler")
@IocBean
public class HttpJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
// valid
if (param==null || param.trim().length()==0) {
XxlJobLogger.log("URL Empty");
return FAIL;
}
// httpGet config
HttpGet httpGet = new HttpGet(param);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpGet.setConfig(requestConfig);
CloseableHttpClient httpClient = null;
try{
httpClient = HttpClients.custom().disableAutomaticRetries().build();
// parse response
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() != 200) {
XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatusLine().getStatusCode());
return FAIL;
}
if (null == entity) {
XxlJobLogger.log("Http Entity Empty.");
return FAIL;
}
String responseMsg = EntityUtils.toString(entity, "UTF-8");
XxlJobLogger.log(responseMsg);
EntityUtils.consume(entity);
return SUCCESS;
} catch (Exception e) {
XxlJobLogger.log(e);
return FAIL;
} finally{
if (httpGet!=null) {
httpGet.releaseConnection();
}
if (httpClient!=null) {
try {
httpClient.close();
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
}
}
}

@ -0,0 +1,78 @@
package com.xxl.job.executor.service.jobhandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* Http
*
* @author xuxueli 2018-09-16 03:48:34
*/
@JobHandler(value="httpJobHandler")
@Component
public class HttpJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
// valid
if (param==null || param.trim().length()==0) {
XxlJobLogger.log("URL Empty");
return FAIL;
}
// httpGet config
HttpGet httpGet = new HttpGet(param);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpGet.setConfig(requestConfig);
CloseableHttpClient httpClient = null;
try{
httpClient = HttpClients.custom().disableAutomaticRetries().build();
// parse response
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() != 200) {
XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatusLine().getStatusCode());
return FAIL;
}
if (null == entity) {
XxlJobLogger.log("Http Entity Empty.");
return FAIL;
}
String responseMsg = EntityUtils.toString(entity, "UTF-8");
XxlJobLogger.log(responseMsg);
EntityUtils.consume(entity);
return SUCCESS;
} catch (Exception e) {
XxlJobLogger.log(e);
return FAIL;
} finally{
if (httpGet!=null) {
httpGet.releaseConnection();
}
if (httpClient!=null) {
try {
httpClient.close();
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
}
}
}

@ -7,7 +7,6 @@ import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil; import com.xxl.job.core.util.ShardingUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* 广 * 广
* *

@ -0,0 +1,78 @@
package com.xxl.job.executor.service.jobhandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* Http
*
* @author xuxueli 2018-09-16 03:48:34
*/
@JobHandler(value="httpJobHandler")
@Component
public class HttpJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
// valid
if (param==null || param.trim().length()==0) {
XxlJobLogger.log("URL Empty");
return FAIL;
}
// httpGet config
HttpGet httpGet = new HttpGet(param);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
httpGet.setConfig(requestConfig);
CloseableHttpClient httpClient = null;
try{
httpClient = HttpClients.custom().disableAutomaticRetries().build();
// parse response
HttpResponse response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() != 200) {
XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatusLine().getStatusCode());
return FAIL;
}
if (null == entity) {
XxlJobLogger.log("Http Entity Empty.");
return FAIL;
}
String responseMsg = EntityUtils.toString(entity, "UTF-8");
XxlJobLogger.log(responseMsg);
EntityUtils.consume(entity);
return SUCCESS;
} catch (Exception e) {
XxlJobLogger.log(e);
return FAIL;
} finally{
if (httpGet!=null) {
httpGet.releaseConnection();
}
if (httpClient!=null) {
try {
httpClient.close();
} catch (IOException e) {
XxlJobLogger.log(e);
}
}
}
}
}

@ -7,7 +7,6 @@ import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil; import com.xxl.job.core.util.ShardingUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* 广 * 广
* *

Loading…
Cancel
Save