diff --git a/README.md b/README.md index c799d2c7fe42714297e32f803df1f0773446855a..fb9bde66eab985d73e3489684214f873c5e35ccd 100644 --- a/README.md +++ b/README.md @@ -99,9 +99,9 @@ XXL-JOB是一个轻量级分布式任务调度框架,其核心设计目标是 ![输入图片说明](https://static.oschina.net/uploads/img/201704/25151032_nrJN.png "在这里输入图片标题") ### 1.5 环境 -- Servlet/JSP Spec:3.0/2.2 +- Servlet/JSP Spec:3.1/2.3 - JDK:1.7+ -- Tomcat:7+/Jetty8+ +- Tomcat:8.5.x+/Jetty9.2+ - Mysql:5.6+ - Maven:3+ @@ -813,6 +813,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 #### 6.14 版本 V1.7.0 特性 (Coding) - 1、脚本任务:支持以GLUE模式开发和运行脚本任务,包括Shell、Python等类型脚本; +- 2、新增spring-boot类型执行器example项目; +- 3、升级jetty版本至9.2; - 2、执行器移除GlueLoader依赖改为推送方式,GLUE源码加载不再依赖JDBC; - 3、登陆拦截Redirect时获取项目名,解决非根据目录发布时跳转404问题; diff --git a/pom.xml b/pom.xml index 31a430a14e15cb581ba37169d4ab3810c9635d00..d191b8b9df72c30c84dd6ef93b76f84df452880b 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,8 @@ xxl-job-core xxl-job-admin xxl-job-executor-example - + xxl-job-executor-springboot-example + diff --git a/xxl-job-core/pom.xml b/xxl-job-core/pom.xml index d3788249b8b1b9f98cbaee2008a315c533f8a011..3faa4c364d5f643cc4c4f5a0c0a359c11ccb4021 100644 --- a/xxl-job-core/pom.xml +++ b/xxl-job-core/pom.xml @@ -34,7 +34,7 @@ org.eclipse.jetty jetty-server - 8.2.0.v20160908 + 9.2.21.v20170120 diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/server/JettyServer.java b/xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/server/JettyServer.java index 09a82336e6ded47a676bde4e595f249415cddfd7..d866fd68fc861d7d0cfd4efaf9edf8d978bcfbf8 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/server/JettyServer.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/rpc/netcom/jetty/server/JettyServer.java @@ -5,8 +5,8 @@ import com.xxl.job.core.thread.ExecutorRegistryThread; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.util.thread.ExecutorThreadPool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,21 +24,22 @@ public class JettyServer { thread = new Thread(new Runnable() { @Override public void run() { - server = new Server(); - server.setThreadPool(new ExecutorThreadPool(200, 200, 30000)); // 非阻塞 - - // connector - SelectChannelConnector connector = new SelectChannelConnector(); + + // The Server + server = new Server(new ExecutorThreadPool()); // 非阻塞 + + // HTTP connector + ServerConnector connector = new ServerConnector(server); connector.setPort(port); - connector.setMaxIdleTime(30000); - server.setConnectors(new Connector[] { connector }); - - // handler - HandlerCollection handlerc =new HandlerCollection(); + server.setConnectors(new Connector[]{connector}); + + // Set a handler + HandlerCollection handlerc =new HandlerCollection(); handlerc.setHandlers(new Handler[]{new JettyServerHandler()}); server.setHandler(handlerc); try { + // Start the server server.start(); logger.info(">>>>>>>>>>>> xxl-job jetty server start success at port:{}.", port); ExecutorRegistryThread.getInstance().start(port, ip, appName, registHelper); diff --git a/xxl-job-executor-springboot-example/pom.xml b/xxl-job-executor-springboot-example/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..4ee928705028c478d3f6341ce5966c718f004b55 --- /dev/null +++ b/xxl-job-executor-springboot-example/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + + com.xuxueli + xxl-job + 1.7.0-SNAPSHOT + + xxl-job-executor-springboot-example + jar + xxl-job-executor-springboot-example + Example executor project for spring boot + + + 1.7.0-SNAPSHOT + + 1.3.8.RELEASE + + UTF-8 + UTF-8 + 1.7 + + + + + + + org.springframework.boot + spring-boot-starter-parent + ${spring-boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-logging + + + + + + org.springframework.boot + spring-boot-starter-log4j + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.mchange + c3p0 + 0.9.5.2 + + + + mysql + mysql-connector-java + 5.1.29 + + + + + com.xuxueli + xxl-job-core + ${xxl-job.version} + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/Application.java b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..51a0e4578adc485b9fc5482964af56e66325aa19 --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/Application.java @@ -0,0 +1,13 @@ +package com.xxl.job.executor; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..4a8c1dae35020e34414eed03bedef04e0f420530 --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java @@ -0,0 +1,11 @@ +package com.xxl.job.executor.core.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + + +@Configuration +@ImportResource("classpath:applicationcontext-xxl-job.xml") +public class XxlJobConfig { + +} \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java new file mode 100644 index 0000000000000000000000000000000000000000..89c7fef45051e163e1ded5c3e23ef3aca73586bf --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/mvc/handler/IndexController.java @@ -0,0 +1,18 @@ +package com.xxl.job.executor.mvc.handler; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@EnableAutoConfiguration +public class IndexController { + + @RequestMapping("/") + @ResponseBody + String index() { + return "xxl job running."; + } + +} \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..8773fc78294f1430e038bc7d9adf88ee59cba61a --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/java/com/xxl/job/executor/service/jobhandler/DemoJobHandler.java @@ -0,0 +1,39 @@ +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.JobHander; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.util.concurrent.TimeUnit; + + +/** + * 任务Handler的一个Demo(Bean模式) + * + * 开发步骤: + * 1、继承 “IJobHandler” ; + * 2、装配到Spring,例如加 “@Service” 注解; + * 3、加 “@JobHander” 注解,注解value值为新增任务生成的JobKey的值;多个JobKey用逗号分割; + * + * @author xuxueli 2015-12-19 19:43:36 + */ +@JobHander(value="demoJobHandler") +@Service +public class DemoJobHandler extends IJobHandler { + private static transient Logger logger = LoggerFactory.getLogger(DemoJobHandler.class); + + @Override + public ReturnT execute(String... params) throws Exception { + logger.info("XXL-JOB, Hello World."); + + for (int i = 0; i < 5; i++) { + logger.info("beat at:{}", i); + TimeUnit.SECONDS.sleep(2); + } + return ReturnT.SUCCESS; + } + +} diff --git a/xxl-job-executor-springboot-example/src/main/resources/application.properties b/xxl-job-executor-springboot-example/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..bafddced850ad5cb9c8b100b9daf64dae4e70202 --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=8081 \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml b/xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml new file mode 100644 index 0000000000000000000000000000000000000000..d4dd0992df17eaad3bbc90042092038207b5ae15 --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/resources/applicationcontext-xxl-job.xml @@ -0,0 +1,59 @@ + + + + + + + + classpath*:xxl-job-executor.properties + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/resources/log4j.xml b/xxl-job-executor-springboot-example/src/main/resources/log4j.xml new file mode 100644 index 0000000000000000000000000000000000000000..b0d1cd87d70143f38b5a52d03d0b402cc0549fdc --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/resources/log4j.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties b/xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties new file mode 100644 index 0000000000000000000000000000000000000000..769c72e0b30df072948138e9404c4ee28c5183c8 --- /dev/null +++ b/xxl-job-executor-springboot-example/src/main/resources/xxl-job-executor.properties @@ -0,0 +1,10 @@ +### xxl-job db +xxl.job.db.driverClass=com.mysql.jdbc.Driver +xxl.job.db.url=jdbc:mysql://localhost:3306/xxl-job?useUnicode=true&characterEncoding=UTF-8 +xxl.job.db.user=root +xxl.job.db.password=root_pwd + +### xxl-job executor address +xxl.job.executor.appname=xxl-job-executor-example +xxl.job.executor.ip= +xxl.job.executor.port=9999 \ No newline at end of file diff --git a/xxl-job-executor-springboot-example/src/test/java/com/xxl/job/executor/test/XxlJobExecutorExampleBootApplicationTests.java b/xxl-job-executor-springboot-example/src/test/java/com/xxl/job/executor/test/XxlJobExecutorExampleBootApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..831ce52a67ba5bc57fa931cc7c313f82c5b97016 --- /dev/null +++ b/xxl-job-executor-springboot-example/src/test/java/com/xxl/job/executor/test/XxlJobExecutorExampleBootApplicationTests.java @@ -0,0 +1,19 @@ +package com.xxl.job.executor.test; + +import com.xxl.job.executor.Application; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = Application.class) +@WebAppConfiguration +public class XxlJobExecutorExampleBootApplicationTests { + + @Test + public void contextLoads() { + } + +} \ No newline at end of file