diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 967ddb49..8750bbb8 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -559,7 +559,6 @@ XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅 xxl-job-core:公共依赖 xxl-job-executor-samples:执行器Sample示例(选择合适的版本执行器,可直接使用,也可以参考其并将现有项目改造成执行器) :xxl-job-executor-sample-springboot:Springboot版本,通过Springboot管理执行器,推荐这种方式; - :xxl-job-executor-sample-spring:Spring版本,通过Spring容器管理执行器,比较通用; :xxl-job-executor-sample-frameless:无框架版本; @@ -714,7 +713,7 @@ public XxlJobSpringExecutor xxlJobExecutor() { 如果已经正确进行上述配置,可将执行器项目编译打部署,系统提供多种执行器Sample示例项目,选择其中一个即可,各自的部署方式如下。 xxl-job-executor-sample-springboot:项目编译打包成springboot类型的可执行JAR包,命令启动即可; - xxl-job-executor-sample-spring:项目编译打包成WAR包,并部署到tomcat中。 + xxl-job-executor-sample-frameless:项目编译打包成JAR包,命令启动即可; 至此“执行器”项目已经部署结束。 diff --git a/pom.xml b/pom.xml index f34feff6..a072628b 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 1.8 true - 4.1.53.Final + 4.1.54.Final 2.8.6 5.2.9.RELEASE diff --git a/xxl-job-executor-samples/pom.xml b/xxl-job-executor-samples/pom.xml index d7e1810c..8f7cdb3f 100644 --- a/xxl-job-executor-samples/pom.xml +++ b/xxl-job-executor-samples/pom.xml @@ -13,7 +13,6 @@ xxl-job-executor-sample-frameless xxl-job-executor-sample-springboot - xxl-job-executor-sample-spring \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/pom.xml b/xxl-job-executor-samples/xxl-job-executor-sample-spring/pom.xml deleted file mode 100644 index 6ea54ecc..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - 4.0.0 - - com.xuxueli - xxl-job-executor-samples - 2.3.0-SNAPSHOT - - xxl-job-executor-sample-spring - war - - ${project.artifactId} - Executor project for spring boot. - https://www.xuxueli.com/ - - - - - org.springframework - spring-webmvc - ${spring.version} - - - - - - org.logback-extensions - logback-ext-spring - 0.1.4 - - - org.slf4j - jcl-over-slf4j - 1.7.25 - - - - - - com.xuxueli - xxl-job-core - ${project.parent.version} - - - - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - false - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java deleted file mode 100644 index 7ea8e52d..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/java/com/xxl/job/executor/service/jobhandler/SampleXxlJob.java +++ /dev/null @@ -1,253 +0,0 @@ -package com.xxl.job.executor.service.jobhandler; - -import com.xxl.job.core.context.XxlJobHelper; -import com.xxl.job.core.handler.annotation.XxlJob; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Arrays; -import java.util.concurrent.TimeUnit; - -/** - * XxlJob开发示例(Bean模式) - * - * 开发步骤: - * 1、任务开发:在Spring Bean实例中,开发Job方法; - * 2、注解配置:为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。 - * 3、执行日志:需要通过 "XxlJobHelper.log" 打印执行日志; - * 4、任务结果:默认任务结果为 "成功" 状态,不需要主动设置;如有诉求,比如设置任务结果为失败,可以通过 "XxlJobHelper.handleFail/handleSuccess" 自主设置任务结果; - * - * @author xuxueli 2019-12-11 21:52:51 - */ -@Component -public class SampleXxlJob { - private static Logger logger = LoggerFactory.getLogger(SampleXxlJob.class); - - - /** - * 1、简单任务示例(Bean模式) - */ - @XxlJob("demoJobHandler") - public void demoJobHandler() throws Exception { - XxlJobHelper.log("XXL-JOB, Hello World."); - - for (int i = 0; i < 5; i++) { - XxlJobHelper.log("beat at:" + i); - TimeUnit.SECONDS.sleep(2); - } - // default success - } - - - /** - * 2、分片广播任务 - */ - @XxlJob("shardingJobHandler") - public void shardingJobHandler() throws Exception { - - // 分片参数 - int shardIndex = XxlJobHelper.getShardIndex(); - int shardTotal = XxlJobHelper.getShardTotal(); - - XxlJobHelper.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal); - - // 业务逻辑 - for (int i = 0; i < shardTotal; i++) { - if (i == shardIndex) { - XxlJobHelper.log("第 {} 片, 命中分片开始处理", i); - } else { - XxlJobHelper.log("第 {} 片, 忽略", i); - } - } - - } - - - /** - * 3、命令行任务 - */ - @XxlJob("commandJobHandler") - public void commandJobHandler() throws Exception { - String command = XxlJobHelper.getJobParam(); - int exitValue = -1; - - BufferedReader bufferedReader = null; - try { - // command process - ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.command(command); - processBuilder.redirectErrorStream(true); - - Process process = processBuilder.start(); - //Process process = Runtime.getRuntime().exec(command); - - BufferedInputStream bufferedInputStream = new BufferedInputStream(process.getInputStream()); - bufferedReader = new BufferedReader(new InputStreamReader(bufferedInputStream)); - - // command log - String line; - while ((line = bufferedReader.readLine()) != null) { - XxlJobHelper.log(line); - } - - // command exit - process.waitFor(); - exitValue = process.exitValue(); - } catch (Exception e) { - XxlJobHelper.log(e); - } finally { - if (bufferedReader != null) { - bufferedReader.close(); - } - } - - if (exitValue == 0) { - // default success - } else { - XxlJobHelper.handleFail("command exit value("+exitValue+") is failed"); - } - - } - - - /** - * 4、跨平台Http任务 - * 参数示例: - * "url: http://www.baidu.com\n" + - * "method: get\n" + - * "data: content\n"; - */ - @XxlJob("httpJobHandler") - public void httpJobHandler() throws Exception { - - // param parse - String param = XxlJobHelper.getJobParam(); - if (param==null || param.trim().length()==0) { - XxlJobHelper.log("param["+ param +"] invalid."); - - XxlJobHelper.handleFail(); - return; - } - - String[] httpParams = param.split("\n"); - String url = null; - String method = null; - String data = null; - for (String httpParam: httpParams) { - if (httpParam.startsWith("url:")) { - url = httpParam.substring(httpParam.indexOf("url:") + 4).trim(); - } - if (httpParam.startsWith("method:")) { - method = httpParam.substring(httpParam.indexOf("method:") + 7).trim().toUpperCase(); - } - if (httpParam.startsWith("data:")) { - data = httpParam.substring(httpParam.indexOf("data:") + 5).trim(); - } - } - - // param valid - if (url==null || url.trim().length()==0) { - XxlJobHelper.log("url["+ url +"] invalid."); - - XxlJobHelper.handleFail(); - return; - } - if (method==null || !Arrays.asList("GET", "POST").contains(method)) { - XxlJobHelper.log("method["+ method +"] invalid."); - - XxlJobHelper.handleFail(); - return; - } - boolean isPostMethod = method.equals("POST"); - - // request - HttpURLConnection connection = null; - BufferedReader bufferedReader = null; - try { - // connection - URL realUrl = new URL(url); - connection = (HttpURLConnection) realUrl.openConnection(); - - // connection setting - connection.setRequestMethod(method); - connection.setDoOutput(isPostMethod); - connection.setDoInput(true); - connection.setUseCaches(false); - connection.setReadTimeout(5 * 1000); - connection.setConnectTimeout(3 * 1000); - connection.setRequestProperty("connection", "Keep-Alive"); - connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); - connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8"); - - // do connection - connection.connect(); - - // data - if (isPostMethod && data!=null && data.trim().length()>0) { - DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); - dataOutputStream.write(data.getBytes("UTF-8")); - dataOutputStream.flush(); - dataOutputStream.close(); - } - - // valid StatusCode - int statusCode = connection.getResponseCode(); - if (statusCode != 200) { - throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid."); - } - - // result - bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); - StringBuilder result = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - result.append(line); - } - String responseMsg = result.toString(); - - XxlJobHelper.log(responseMsg); - - return; - } catch (Exception e) { - XxlJobHelper.log(e); - - XxlJobHelper.handleFail(); - return; - } finally { - try { - if (bufferedReader != null) { - bufferedReader.close(); - } - if (connection != null) { - connection.disconnect(); - } - } catch (Exception e2) { - XxlJobHelper.log(e2); - } - } - - } - - /** - * 5、生命周期任务示例:任务初始化与销毁时,支持自定义相关逻辑; - */ - @XxlJob(value = "demoJobHandler2", init = "init", destroy = "destroy") - public void demoJobHandler2() throws Exception { - XxlJobHelper.log("XXL-JOB, Hello World."); - } - public void init(){ - logger.info("init"); - } - public void destroy(){ - logger.info("destory"); - } - - -} diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml deleted file mode 100644 index 1ff9421d..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - classpath*:xxl-job-executor.properties - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/log4j.xml b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/log4j.xml deleted file mode 100644 index f0a7fc65..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/log4j.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/logback.xml b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/logback.xml deleted file mode 100644 index d5a0d2ca..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/logback.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - logback - - - - - %d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n - - - - - ${log.path} - - ${log.path}.%d{yyyy-MM-dd}.zip - - - %date %level [%thread] %logger{36} [%file : %line] %msg%n - - - - - - - - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/xxl-job-executor.properties b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/xxl-job-executor.properties deleted file mode 100644 index ea7589af..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/xxl-job-executor.properties +++ /dev/null @@ -1,17 +0,0 @@ -### 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= - -### xxl-job executor appname -xxl.job.executor.appname=xxl-job-executor-sample -### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null -xxl.job.executor.address= -### xxl-job executor server-info -xxl.job.executor.ip= -xxl.job.executor.port=9999 -### xxl-job executor log-path -xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler -### xxl-job executor log-retention-days -xxl.job.executor.logretentiondays=30 \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/WEB-INF/web.xml b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index c32feb32..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - xxl-job-executor-sample-spring - - webAppRootKey - xxl-job-executor-sample-spring - - - - - contextConfigLocation - classpath*:applicationcontext-*.xml - - - - - logbackConfigLocation - classpath:logback.xml - - - - ch.qos.logback.ext.spring.web.LogbackConfigListener - - - - org.springframework.web.context.ContextLoaderListener - - - - index.html - - - \ No newline at end of file diff --git a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/index.html b/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/index.html deleted file mode 100644 index 7085239b..00000000 --- a/xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/webapp/index.html +++ /dev/null @@ -1 +0,0 @@ -i am alive. \ No newline at end of file