├── .travis.yml ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── micro-job-samples ├── sample-registry-memory │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── registry │ │ │ └── memory │ │ │ └── SampleRegistryMemoryApplication.java │ └── pom.xml ├── sample-consumer │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── consumer │ │ │ ├── SampleConsumerApplication.java │ │ │ └── jobs │ │ │ └── SampleJob.java │ └── pom.xml ├── sample-provider │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── provider │ │ │ └── SampleProviderApplication.java │ └── pom.xml ├── sample-registry-redis │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── redis │ │ │ └── SampleRegistryRedisApplication.java │ └── pom.xml ├── sample-registry-consul │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── SampleRegistryConsulApplication.java │ └── pom.xml ├── sample-registry-zookeeper │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── zookeeper │ │ │ └── SampleRegistryZookeeperApplication.java │ └── pom.xml ├── sample-schedule │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── github │ │ │ └── hengboy │ │ │ └── sample │ │ │ └── schedule │ │ │ └── SampleScheduleApplication.java │ └── pom.xml ├── README.md └── pom.xml ├── .gitignore ├── micro-job-starters ├── spring-boot-starter │ └── pom.xml ├── spring-boot-starter-consumer │ ├── pom.xml │ └── spring-boot-starter-consumer.iml ├── spring-boot-starter-provider │ └── pom.xml ├── spring-boot-starter-registry-memory │ └── pom.xml ├── spring-boot-starter-registry-redis │ └── pom.xml ├── spring-boot-starter-registry-consul │ └── pom.xml ├── spring-boot-starter-registry-zookeeper │ └── pom.xml ├── pom.xml ├── spring-boot-starter-schedule │ └── pom.xml └── spring-boot-starter-registry-nacos │ └── pom.xml ├── micro-job-autoconfigure ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── spring.factories │ │ └── java │ │ └── com │ │ └── github │ │ └── hengboy │ │ └── job │ │ └── autoconfigure │ │ ├── provider │ │ ├── MicroJobProviderProperties.java │ │ └── MicroJobProviderAutoConfiguration.java │ │ ├── consumer │ │ ├── MicroJobConsumerProperties.java │ │ └── MicroJobConsumerAutoConfiguration.java │ │ ├── registry │ │ ├── MicroJobRegistryAutoConfiguration.java │ │ ├── MicroJobMemoryRegistryAutoConfiguration.java │ │ ├── MicroJobRedisRegistryAutoConfiguration.java │ │ ├── MicroJobConsulRegistryAutoConfiguration.java │ │ ├── MicroJobNacosRegistryAutoConfiguration.java │ │ ├── MicroJobZookeeperRegistryAutoConfiguration.java │ │ └── MicroJobRegistryProperties.java │ │ └── schedule │ │ ├── MicroJobScheduleProperties.java │ │ ├── MicroJobScheduleAutoConfiguration.java │ │ └── MicroJobQuartzAutoConfiguration.java └── pom.xml ├── pom.xml ├── README_zh.md ├── mvnw.cmd ├── README.md ├── mvnw ├── micro-job-dependencies └── pom.xml └── LICENSE /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-memory/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-registry-memory 4 | # http port 5 | # micro job registry port 6 | server: 7 | port: 7000 8 | hengboy: 9 | job: 10 | # 任务注册中心 11 | registry: 12 | # 内存方式 13 | away: memory 14 | -------------------------------------------------------------------------------- /micro-job-samples/sample-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-consumer 4 | # http port 5 | server: 6 | port: 10000 7 | hengboy: 8 | job: 9 | # 任务注册中心 10 | registry: 11 | port: 7000 12 | # ip地址,默认:127.0.0.1 13 | # ip-address: 127.0.0.1 14 | # 任务注册中心方式,默认memory 15 | # away: memory 16 | -------------------------------------------------------------------------------- /micro-job-samples/sample-provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-provider 4 | # http port 5 | server: 6 | port: 8000 7 | hengboy: 8 | job: 9 | # 任务注册中心 10 | registry: 11 | port: 7000 12 | # ip地址,默认:127.0.0.1 13 | # ip-address: 127.0.0.1 14 | # 任务注册中心方式,默认memory 15 | # away: memory 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-registry-redis 4 | # redis相关配置 5 | redis: 6 | host: xxx.xxx.xxx.xx 7 | password: xxxxx 8 | # http port 9 | # micro job registry port 10 | server: 11 | port: 7000 12 | 13 | hengboy: 14 | job: 15 | # 任务注册中心 16 | registry: 17 | away: redis 18 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-consul/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-registry-consul 4 | # http port 5 | # micro job registry port 6 | server: 7 | port: 7000 8 | hengboy: 9 | job: 10 | # 任务注册中心 11 | registry: 12 | away: consul 13 | # consul配置 14 | consul: 15 | address: "127.0.0.1" 16 | port: 8500 17 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-zookeeper/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-registry-zookeeper 4 | hengboy: 5 | job: 6 | # 任务注册中心 7 | registry: 8 | away: zookeeper 9 | # zookeeper配置信息 10 | zookeeper: 11 | address: "127.0.0.1:2181" 12 | # http port 13 | # micro job registry port 14 | server: 15 | port: 7000 16 | -------------------------------------------------------------------------------- /micro-job-samples/sample-schedule/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: sample-schedule 4 | # http port 5 | server: 6 | port: 11000 7 | hengboy: 8 | job: 9 | registry: 10 | port: 7000 11 | # ip地址,默认:127.0.0.1 12 | # ip-address: 127.0.0.1 13 | # 任务注册中心方式,默认memory 14 | # away: memory 15 | schedule: 16 | job-store-type: memory 17 | -------------------------------------------------------------------------------- /micro-job-samples/README.md: -------------------------------------------------------------------------------- 1 | ### 目录结构 2 | 3 | ``` 4 | . 5 | ├── sample-consumer 6 | ├── sample-provider 7 | ├── sample-registry-memory 8 | ├── sample-registry-redis 9 | ├── sample-registry-zookeeper 10 | ├── sample-schedule 11 | ├── pom.xml 12 | └── README.md 13 | ``` 14 | 15 | ### 项目介绍 16 | 17 | - sample-consumer 18 | 19 | 任务消费者项目示例 20 | 21 | - sample-provider 22 | 23 | 任务生产者项目示例 24 | 25 | - sample-registry-memory 26 | 27 | 任务注册中心 - 内存方式示例 28 | 29 | - sample-registry-redis 30 | 31 | 任务注册中心 - Redis方式示例 32 | 33 | - sample-registry-zookeeper 34 | 35 | 任务注册中心 - Zookeeper方式示例 36 | 37 | - sample-schedule 38 | 39 | 任务调度器项目示例 -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter 13 | 14 | 15 | 16 | 17 | com.github.hengboy 18 | micro-job-autoconfigure 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | # Auto Configure 2 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 3 | com.github.hengboy.job.autoconfigure.schedule.MicroJobScheduleAutoConfiguration,\ 4 | com.github.hengboy.job.autoconfigure.schedule.MicroJobQuartzAutoConfiguration,\ 5 | com.github.hengboy.job.autoconfigure.provider.MicroJobProviderAutoConfiguration,\ 6 | com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryAutoConfiguration,\ 7 | com.github.hengboy.job.autoconfigure.registry.MicroJobMemoryRegistryAutoConfiguration,\ 8 | com.github.hengboy.job.autoconfigure.registry.MicroJobRedisRegistryAutoConfiguration,\ 9 | com.github.hengboy.job.autoconfigure.registry.MicroJobZookeeperRegistryAutoConfiguration,\ 10 | com.github.hengboy.job.autoconfigure.registry.MicroJobConsulRegistryAutoConfiguration,\ 11 | com.github.hengboy.job.autoconfigure.registry.MicroJobNacosRegistryAutoConfiguration,\ 12 | com.github.hengboy.job.autoconfigure.consumer.MicroJobConsumerAutoConfiguration 13 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter-consumer 13 | 14 | 15 | 16 | 17 | com.github.hengboy 18 | spring-boot-starter 19 | 20 | 21 | 22 | com.github.hengboy 23 | micro-job-consumer 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter-provider 13 | 14 | 15 | 16 | 17 | com.github.hengboy 18 | spring-boot-starter 19 | 20 | 21 | 22 | com.github.hengboy 23 | micro-job-provider 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-registry-memory/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter-registry-memory 13 | 14 | 15 | 16 | 17 | com.github.hengboy 18 | spring-boot-starter 19 | 20 | 21 | 22 | com.github.hengboy 23 | micro-job-registry-memory 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-registry-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter-registry-redis 13 | 14 | 15 | 16 | 17 | com.github.hengboy 18 | spring-boot-starter 19 | 20 | 21 | 22 | com.github.hengboy 23 | micro-job-registry-redis 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-registry-consul/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter-registry-consul 13 | 14 | 15 | 16 | com.github.hengboy 17 | spring-boot-starter 18 | 19 | 20 | 21 | com.github.hengboy 22 | micro-job-registry-consul 23 | 24 | 25 | 26 | com.orbitz.consul 27 | consul-client 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /micro-job-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-micro-job 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | micro-job-samples 13 | pom 14 | 15 | 16 | 17 | org.apache.maven.plugins 18 | maven-deploy-plugin 19 | 2.8.2 20 | 21 | true 22 | 23 | 24 | 25 | 26 | 27 | sample-provider 28 | sample-registry-memory 29 | sample-consumer 30 | sample-schedule 31 | sample-registry-redis 32 | sample-registry-zookeeper 33 | sample-registry-consul 34 | 35 | 36 | -------------------------------------------------------------------------------- /micro-job-samples/sample-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-consumer 29 | 30 | 31 | 32 | com.github.hengboy 33 | spring-boot-starter-consumer 34 | ${parent.version} 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-job-samples/sample-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-provider 29 | 30 | 31 | 32 | com.github.hengboy 33 | spring-boot-starter-provider 34 | ${parent.version} 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-job-samples/sample-schedule/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-schedule 29 | 30 | 31 | 32 | com.github.hengboy 33 | spring-boot-starter-schedule 34 | ${parent.version} 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-consul/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-registry-consul 29 | 30 | 31 | 32 | 33 | com.github.hengboy 34 | spring-boot-starter-registry-consul 35 | ${parent.version} 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-memory/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-registry-memory 29 | 30 | 31 | 32 | 33 | com.github.hengboy 34 | spring-boot-starter-registry-memory 35 | ${parent.version} 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-zookeeper/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-registry-zookeeper 29 | 30 | 31 | 32 | 33 | com.github.hengboy 34 | spring-boot-starter-registry-zookeeper 35 | ${parent.version} 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-registry-zookeeper/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | spring-boot-starter-registry-zookeeper 13 | 14 | 0.11 15 | 16 | 17 | 18 | 19 | com.github.hengboy 20 | spring-boot-starter 21 | 22 | 23 | 24 | com.github.hengboy 25 | micro-job-registry-zookeeper 26 | 27 | 28 | 29 | com.101tec 30 | zkclient 31 | ${zkclient.version} 32 | 33 | 34 | org.slf4j 35 | slf4j-log4j12 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /micro-job-starters/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-micro-job 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | micro-job-starters 13 | pom 14 | 15 | spring-boot-starter-schedule 16 | spring-boot-starter-consumer 17 | spring-boot-starter-provider 18 | spring-boot-starter-registry-zookeeper 19 | spring-boot-starter-registry-consul 20 | spring-boot-starter-registry-redis 21 | spring-boot-starter-registry-memory 22 | spring-boot-starter 23 | spring-boot-starter-registry-nacos 24 | 25 | 26 | 27 | 28 | 29 | com.github.hengboy 30 | micro-job-dependencies 31 | ${micro.job.dependencies.version} 32 | pom 33 | import 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/provider/MicroJobProviderProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.provider; 18 | 19 | import com.github.hengboy.job.core.enums.LoadBalanceStrategy; 20 | import lombok.Data; 21 | import org.springframework.boot.context.properties.ConfigurationProperties; 22 | 23 | /** 24 | * 任务生产者属性配置 25 | * 26 | * @author:恒宇少年 - 于起宇 27 | *

28 | * DateTime:2019-01-29 14:49 29 | * Blog:http://blog.yuqiyu.com 30 | * WebSite:http://www.jianshu.com/u/092df3f77bca 31 | * Gitee:https://gitee.com/hengboy 32 | * GitHub:https://github.com/hengyuboy 33 | */ 34 | @Data 35 | @ConfigurationProperties(prefix = "hengboy.job.provider") 36 | public class MicroJobProviderProperties { 37 | /** 38 | * 调度器调用负载均衡策略 39 | */ 40 | private LoadBalanceStrategy scheduleLbStrategy = LoadBalanceStrategy.POLL_WEIGHT; 41 | /** 42 | * 同步注册中心调度器间隔时间 43 | * 单位:秒 44 | */ 45 | private int syncRegistryScheduleIntervalSeconds = 5; 46 | } 47 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/consumer/MicroJobConsumerProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.consumer; 18 | 19 | import lombok.Data; 20 | import org.springframework.boot.context.properties.ConfigurationProperties; 21 | 22 | /** 23 | * 任务消费者属性配置 24 | * 25 | * @author:恒宇少年 - 于起宇 26 | *

27 | * DateTime:2019-01-30 15:26 28 | * Blog:http://blog.yuqiyu.com 29 | * WebSite:http://www.jianshu.com/u/092df3f77bca 30 | * Gitee:https://gitee.com/hengboy 31 | * GitHub:https://github.com/hengyuboy 32 | */ 33 | @Data 34 | @ConfigurationProperties(prefix = "hengboy.job.consumer") 35 | public class MicroJobConsumerProperties { 36 | /** 37 | * 调度器负载的权重 38 | */ 39 | private int loadBalanceWeight = 1; 40 | /** 41 | * 心跳同步执行间隔时间,单位:秒 42 | */ 43 | private int heartDelaySeconds = 5; 44 | /** 45 | * 扫描microJob接口实现类的package 46 | * 默认使用springboot默认扫描bean的package 47 | */ 48 | private String baseScanMicroJobPackage; 49 | } 50 | -------------------------------------------------------------------------------- /micro-job-samples/sample-schedule/src/main/java/com/github/hengboy/sample/schedule/SampleScheduleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.schedule; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * schedule sample application main class 26 | * @author:恒宇少年 - 于起宇 27 | *

28 | * DateTime:2019-02-22 14:03 29 | * Blog:http://blog.yuqiyu.com 30 | * WebSite:http://www.jianshu.com/u/092df3f77bca 31 | * Gitee:https://gitee.com/hengboy 32 | * GitHub:https://github.com/hengyuboy 33 | */ 34 | @SpringBootApplication 35 | public class SampleScheduleApplication { 36 | /** 37 | * logger instance 38 | */ 39 | static Logger logger = LoggerFactory.getLogger(SampleScheduleApplication.class); 40 | 41 | public static void main(String[] args) { 42 | SpringApplication.run(SampleScheduleApplication.class); 43 | logger.info("「「「「「Micro Job Schedule Started」」」」」"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /micro-job-samples/sample-consumer/src/main/java/com/github/hengboy/sample/consumer/SampleConsumerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.consumer; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * consumer sample application main class 26 | * 27 | * @author:恒宇少年 - 于起宇 28 | *

29 | * DateTime:2019-02-22 13:58 30 | * Blog:http://blog.yuqiyu.com 31 | * WebSite:http://www.jianshu.com/u/092df3f77bca 32 | * Gitee:https://gitee.com/hengboy 33 | * GitHub:https://github.com/hengyuboy 34 | */ 35 | @SpringBootApplication 36 | public class SampleConsumerApplication { 37 | /** 38 | * logger instance 39 | */ 40 | static Logger logger = LoggerFactory.getLogger(SampleConsumerApplication.class); 41 | 42 | public static void main(String[] args) { 43 | SpringApplication.run(SampleConsumerApplication.class); 44 | logger.info("「「「「「Micro Job Consumer Started」」」」」"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-job-samples/sample-provider/src/main/java/com/github/hengboy/sample/provider/SampleProviderApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.provider; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * provider sample application main class 26 | * 27 | * @author:恒宇少年 - 于起宇 28 | *

29 | * DateTime:2019-02-22 13:30 30 | * Blog:http://blog.yuqiyu.com 31 | * WebSite:http://www.jianshu.com/u/092df3f77bca 32 | * Gitee:https://gitee.com/hengboy 33 | * GitHub:https://github.com/hengyuboy 34 | */ 35 | @SpringBootApplication 36 | public class SampleProviderApplication { 37 | /** 38 | * logger instance 39 | */ 40 | static Logger logger = LoggerFactory.getLogger(SampleProviderApplication.class); 41 | 42 | public static void main(String[] args) { 43 | SpringApplication.run(SampleProviderApplication.class); 44 | logger.info("「「「「「Micro Job Provider Started」」」」」"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-consul/src/main/java/com/github/hengboy/sample/SampleRegistryConsulApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * consul registry sample application main class 26 | * @author:恒宇少年 - 于起宇 27 | *

28 | * DateTime:2019-02-22 15:35 29 | * Blog:http://blog.yuqiyu.com 30 | * WebSite:http://www.jianshu.com/u/092df3f77bca 31 | * Gitee:https://gitee.com/hengboy 32 | * GitHub:https://github.com/hengyuboy 33 | */ 34 | @SpringBootApplication 35 | public class SampleRegistryConsulApplication { 36 | /** 37 | * logger instance 38 | */ 39 | static Logger logger = LoggerFactory.getLogger(SampleRegistryConsulApplication.class); 40 | 41 | public static void main(String[] args) { 42 | SpringApplication.run(SampleRegistryConsulApplication.class); 43 | logger.info("「「「「「Micro Job Consul Registry Started」」」」」"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-redis/src/main/java/com/github/hengboy/sample/redis/SampleRegistryRedisApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.redis; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * redis registry sample application main class 26 | * 27 | * @author:恒宇少年 - 于起宇 28 | *

29 | * DateTime:2019-02-22 14:13 30 | * Blog:http://blog.yuqiyu.com 31 | * WebSite:http://www.jianshu.com/u/092df3f77bca 32 | * Gitee:https://gitee.com/hengboy 33 | * GitHub:https://github.com/hengyuboy 34 | */ 35 | @SpringBootApplication 36 | public class SampleRegistryRedisApplication { 37 | /** 38 | * logger instance 39 | */ 40 | static Logger logger = LoggerFactory.getLogger(SampleRegistryRedisApplication.class); 41 | 42 | public static void main(String[] args) { 43 | SpringApplication.run(SampleRegistryRedisApplication.class); 44 | logger.info("「「「「「Micro Job Redis Registry Started」」」」」"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-schedule/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | micro-job-starters 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | spring-boot-starter-schedule 12 | 13 | 5.1.4.RELEASE 14 | 5.1.4.RELEASE 15 | 16 | 17 | 18 | 19 | com.github.hengboy 20 | spring-boot-starter 21 | 22 | 23 | 24 | com.github.hengboy 25 | micro-job-schedule 26 | 27 | 28 | org.springframework 29 | spring-context-support 30 | ${spring.context.support.version} 31 | compile 32 | 33 | 34 | org.springframework 35 | spring-tx 36 | ${spring.tx.version} 37 | compile 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-memory/src/main/java/com/github/hengboy/sample/registry/memory/SampleRegistryMemoryApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.registry.memory; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * memory registry sample application main class 26 | * 27 | * @author:恒宇少年 - 于起宇 28 | *

29 | * DateTime:2019-02-22 13:37 30 | * Blog:http://blog.yuqiyu.com 31 | * WebSite:http://www.jianshu.com/u/092df3f77bca 32 | * Gitee:https://gitee.com/hengboy 33 | * GitHub:https://github.com/hengyuboy 34 | */ 35 | @SpringBootApplication 36 | public class SampleRegistryMemoryApplication { 37 | /** 38 | * logger instance 39 | */ 40 | static Logger logger = LoggerFactory.getLogger(SampleRegistryMemoryApplication.class); 41 | 42 | public static void main(String[] args) { 43 | SpringApplication.run(SampleRegistryMemoryApplication.class); 44 | logger.info("「「「「「Micro Job Memory Registry Started」」」」」"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-zookeeper/src/main/java/com/github/hengboy/sample/zookeeper/SampleRegistryZookeeperApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.zookeeper; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.boot.SpringApplication; 22 | import org.springframework.boot.autoconfigure.SpringBootApplication; 23 | 24 | /** 25 | * zookeeper registry sample application main class 26 | * @author:恒宇少年 - 于起宇 27 | *

28 | * DateTime:2019-02-22 14:21 29 | * Blog:http://blog.yuqiyu.com 30 | * WebSite:http://www.jianshu.com/u/092df3f77bca 31 | * Gitee:https://gitee.com/hengboy 32 | * GitHub:https://github.com/hengyuboy 33 | */ 34 | @SpringBootApplication 35 | public class SampleRegistryZookeeperApplication { 36 | /** 37 | * logger instance 38 | */ 39 | static Logger logger = LoggerFactory.getLogger(SampleRegistryZookeeperApplication.class); 40 | 41 | public static void main(String[] args) { 42 | SpringApplication.run(SampleRegistryZookeeperApplication.class); 43 | logger.info("「「「「「Micro Job Zookeeper Registry Started」」」」」"); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /micro-job-samples/sample-registry-redis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-samples 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | sample-registry-redis 29 | 30 | 31 | 32 | 33 | com.github.hengboy 34 | spring-boot-starter-registry-redis 35 | ${parent.version} 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-data-redis 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /micro-job-samples/sample-consumer/src/main/java/com/github/hengboy/sample/consumer/jobs/SampleJob.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.sample.consumer.jobs; 18 | 19 | import com.github.hengboy.job.core.annotation.Job; 20 | import com.github.hengboy.job.core.exception.JobException; 21 | import com.github.hengboy.job.core.model.MicroJob; 22 | import com.github.hengboy.job.core.model.execute.JobExecuteParam; 23 | import com.github.hengboy.job.core.model.execute.JobExecuteResult; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | /** 28 | * job sample 29 | * 30 | * @author:恒宇少年 - 于起宇 31 | *

32 | * DateTime:2019-02-22 15:20 33 | * Blog:http://blog.yuqiyu.com 34 | * WebSite:http://www.jianshu.com/u/092df3f77bca 35 | * Gitee:https://gitee.com/hengboy 36 | * GitHub:https://github.com/hengyuboy 37 | */ 38 | @Job 39 | public class SampleJob implements MicroJob { 40 | /** 41 | * logger instance 42 | */ 43 | static Logger logger = LoggerFactory.getLogger(SampleJob.class); 44 | 45 | @Override 46 | public JobExecuteResult execute(JobExecuteParam param) throws JobException { 47 | logger.info("jobKey -> {}", param.getJobKey()); 48 | logger.info("jobQueueId -> {}", param.getJobQueueId()); 49 | logger.info("jsonParam -> {}", param.getJsonParam()); 50 | 51 | // job logic.. 52 | 53 | return JobExecuteResult.JOB_EXECUTE_SUCCESS; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobRegistryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.github.hengboy.job.core.http.MicroJobRestTemplate; 20 | import com.github.hengboy.job.registry.store.RegistryFactoryBean; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.Configuration; 25 | 26 | /** 27 | * @author:恒宇少年 - 于起宇 28 | *

29 | * DateTime:2019-02-11 14:55 30 | * Blog:http://blog.yuqiyu.com 31 | * WebSite:http://www.jianshu.com/u/092df3f77bca 32 | * Gitee:https://gitee.com/hengboy 33 | * GitHub:https://github.com/hengyuboy 34 | */ 35 | @Configuration 36 | @ConditionalOnClass(RegistryFactoryBean.class) 37 | public class MicroJobRegistryAutoConfiguration { 38 | /** 39 | * 实例化restTemplate 40 | * 用于消费者、提供者、调度器、注册中心ws请求交互 41 | * 42 | * @return 43 | */ 44 | @Bean 45 | @ConditionalOnMissingBean 46 | public MicroJobRestTemplate restTemplate() { 47 | return new MicroJobRestTemplate(); 48 | } 49 | 50 | /** 51 | * 任务注册中心工程实体类 52 | * 53 | * @return 54 | */ 55 | @Bean 56 | @ConditionalOnMissingBean 57 | public RegistryFactoryBean RegistryFactoryBean() { 58 | return new RegistryFactoryBean(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-registry-nacos/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | micro-job-starters 23 | com.github.hengboy 24 | 0.0.3.RELEASE 25 | 26 | 4.0.0 27 | 28 | spring-boot-starter-registry-nacos 29 | 30 | 31 | 32 | com.github.hengboy 33 | spring-boot-starter 34 | 35 | 36 | com.github.hengboy 37 | micro-job-registry-nacos 38 | 39 | 40 | 41 | com.alibaba.boot 42 | nacos-discovery-spring-boot-starter 43 | 44 | 45 | com.alibaba.nacos 46 | nacos-client 47 | 48 | 49 | 50 | 51 | com.alibaba.nacos 52 | nacos-client 53 | 0.8.2 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobMemoryRegistryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.github.hengboy.job.registry.http.InstanceRegistry; 20 | import com.github.hengboy.job.registry.store.RegistryFactoryBean; 21 | import com.github.hengboy.job.registry.support.memory.MemoryInstanceRegistry; 22 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 26 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 27 | import org.springframework.context.annotation.Bean; 28 | import org.springframework.context.annotation.Configuration; 29 | 30 | import static com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties.REGISTRY_PROPERTIES_PREFIX; 31 | 32 | /** 33 | * 内存方式注册中心自动化配置 34 | * 35 | * @author:恒宇少年 - 于起宇 36 | *

37 | * DateTime:2019-01-30 09:55 38 | * Blog:http://blog.yuqiyu.com 39 | * WebSite:http://www.jianshu.com/u/092df3f77bca 40 | * Gitee:https://gitee.com/hengboy 41 | * GitHub:https://github.com/hengyuboy 42 | */ 43 | @Configuration 44 | @ConditionalOnClass({MemoryInstanceRegistry.class, RegistryFactoryBean.class}) 45 | @EnableConfigurationProperties(MicroJobRegistryProperties.class) 46 | @ConditionalOnProperty(prefix = REGISTRY_PROPERTIES_PREFIX, name = "away", havingValue = "MEMORY") 47 | @AutoConfigureAfter(MicroJobRegistryAutoConfiguration.class) 48 | public class MicroJobMemoryRegistryAutoConfiguration { 49 | /** 50 | * 实例注册中心 51 | * 52 | * @return 53 | */ 54 | @Bean 55 | @ConditionalOnMissingBean 56 | public InstanceRegistry instanceRegistry() { 57 | return new MemoryInstanceRegistry(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobRedisRegistryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.github.hengboy.job.registry.http.InstanceRegistry; 20 | import com.github.hengboy.job.registry.store.RegistryFactoryBean; 21 | import com.github.hengboy.job.registry.support.redis.RedisInstanceRegistry; 22 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 26 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 27 | import org.springframework.context.annotation.Bean; 28 | import org.springframework.context.annotation.Configuration; 29 | import org.springframework.data.redis.core.RedisTemplate; 30 | 31 | import static com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties.REGISTRY_PROPERTIES_PREFIX; 32 | 33 | /** 34 | * redis注册方式注册中心自动化配置 35 | * 36 | * @author:恒宇少年 - 于起宇 37 | *

38 | * DateTime:2019-02-13 15:08 39 | * Blog:http://blog.yuqiyu.com 40 | * WebSite:http://www.jianshu.com/u/092df3f77bca 41 | * Gitee:https://gitee.com/hengboy 42 | * GitHub:https://github.com/hengyuboy 43 | */ 44 | @Configuration 45 | @ConditionalOnClass({RedisInstanceRegistry.class, RegistryFactoryBean.class, RedisTemplate.class}) 46 | @EnableConfigurationProperties(MicroJobRegistryProperties.class) 47 | @ConditionalOnProperty(prefix = REGISTRY_PROPERTIES_PREFIX, name = "away", havingValue = "REDIS") 48 | @AutoConfigureAfter(MicroJobRegistryAutoConfiguration.class) 49 | public class MicroJobRedisRegistryAutoConfiguration { 50 | /** 51 | * 实例注册中心 52 | * 53 | * @return 54 | */ 55 | @Bean 56 | @ConditionalOnMissingBean 57 | public InstanceRegistry instanceRegistry() { 58 | return new RedisInstanceRegistry(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobConsulRegistryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.github.hengboy.job.registry.http.InstanceRegistry; 20 | import com.github.hengboy.job.registry.store.RegistryFactoryBean; 21 | import com.github.hengboy.job.registry.support.consul.ConsulInstanceRegistry; 22 | import com.orbitz.consul.AgentClient; 23 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 27 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.Configuration; 30 | 31 | import static com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties.REGISTRY_PROPERTIES_PREFIX; 32 | 33 | /** 34 | * @author:恒宇少年 - 于起宇 35 | *

36 | * DateTime:2019-02-14 17:14 37 | * Blog:http://blog.yuqiyu.com 38 | * WebSite:http://www.jianshu.com/u/092df3f77bca 39 | * Gitee:https://gitee.com/hengboy 40 | * GitHub:https://github.com/hengyuboy 41 | */ 42 | 43 | @Configuration 44 | @ConditionalOnClass({ConsulInstanceRegistry.class, RegistryFactoryBean.class, AgentClient.class}) 45 | @EnableConfigurationProperties(MicroJobRegistryProperties.class) 46 | @ConditionalOnProperty(prefix = REGISTRY_PROPERTIES_PREFIX, name = "away", havingValue = "CONSUL") 47 | @AutoConfigureAfter(MicroJobRegistryAutoConfiguration.class) 48 | public class MicroJobConsulRegistryAutoConfiguration { 49 | /** 50 | * 注册中心配置属性 51 | */ 52 | private MicroJobRegistryProperties microJobRegistryProperties; 53 | 54 | public MicroJobConsulRegistryAutoConfiguration(MicroJobRegistryProperties microJobRegistryProperties) { 55 | this.microJobRegistryProperties = microJobRegistryProperties; 56 | } 57 | 58 | /** 59 | * 实例注册中心 60 | * 61 | * @return 62 | */ 63 | @Bean 64 | @ConditionalOnMissingBean 65 | public InstanceRegistry instanceRegistry() { 66 | return new ConsulInstanceRegistry(microJobRegistryProperties.getConsul().getAddress(), microJobRegistryProperties.getConsul().getPort()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobNacosRegistryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.alibaba.boot.nacos.discovery.autoconfigure.NacosDiscoveryAutoConfiguration; 20 | import com.alibaba.nacos.api.annotation.NacosInjected; 21 | import com.alibaba.nacos.api.naming.NamingService; 22 | import com.github.hengboy.job.registry.http.InstanceRegistry; 23 | import com.github.hengboy.job.registry.store.RegistryFactoryBean; 24 | import com.github.hengboy.job.registry.support.nacos.NacosInstanceRegistry; 25 | import com.github.hengboy.job.registry.support.nacos.resource.NacosRegistryResource; 26 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 30 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 31 | import org.springframework.context.annotation.Bean; 32 | import org.springframework.context.annotation.Configuration; 33 | 34 | import static com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties.REGISTRY_PROPERTIES_PREFIX; 35 | 36 | /** 37 | * nacos registry auto configuration 38 | * 39 | * @author:恒宇少年 - 于起宇 40 | *

41 | * DateTime:2019-02-26 14:07 42 | * Blog:http://blog.yuqiyu.com 43 | * WebSite:http://www.jianshu.com/u/092df3f77bca 44 | * Gitee:https://gitee.com/hengboy 45 | * GitHub:https://github.com/hengyuboy 46 | */ 47 | @Configuration 48 | @ConditionalOnClass({NacosInstanceRegistry.class, RegistryFactoryBean.class, NamingService.class}) 49 | @EnableConfigurationProperties(MicroJobRegistryProperties.class) 50 | @ConditionalOnProperty(prefix = REGISTRY_PROPERTIES_PREFIX, name = "away", havingValue = "NACOS") 51 | @AutoConfigureAfter({MicroJobRegistryAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class}) 52 | public class MicroJobNacosRegistryAutoConfiguration { 53 | 54 | @NacosInjected 55 | private NamingService namingService; 56 | 57 | /** 58 | * 实例注册中心 59 | * 60 | * @return 61 | */ 62 | @Bean 63 | @ConditionalOnMissingBean 64 | public InstanceRegistry instanceRegistry() { 65 | NacosRegistryResource.setNamingService(namingService); 66 | return new NacosInstanceRegistry(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobZookeeperRegistryAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.github.hengboy.job.registry.http.InstanceRegistry; 20 | import com.github.hengboy.job.registry.store.RegistryFactoryBean; 21 | import com.github.hengboy.job.registry.support.zookeeper.ZookeeperInstanceRegistry; 22 | import org.I0Itec.zkclient.ZkClient; 23 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 27 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.Configuration; 30 | 31 | import static com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties.REGISTRY_PROPERTIES_PREFIX; 32 | 33 | /** 34 | * zookeeper任务注册中心实现方式 35 | * 36 | * @author:恒宇少年 - 于起宇 37 | *

38 | * DateTime:2019-02-14 15:08 39 | * Blog:http://blog.yuqiyu.com 40 | * WebSite:http://www.jianshu.com/u/092df3f77bca 41 | * Gitee:https://gitee.com/hengboy 42 | * GitHub:https://github.com/hengyuboy 43 | */ 44 | @Configuration 45 | @ConditionalOnClass({ZookeeperInstanceRegistry.class, RegistryFactoryBean.class, ZkClient.class}) 46 | @EnableConfigurationProperties(MicroJobRegistryProperties.class) 47 | @ConditionalOnProperty(prefix = REGISTRY_PROPERTIES_PREFIX, name = "away", havingValue = "ZOOKEEPER") 48 | @AutoConfigureAfter(MicroJobRegistryAutoConfiguration.class) 49 | public class MicroJobZookeeperRegistryAutoConfiguration { 50 | /** 51 | * 注册中心配置属性 52 | */ 53 | private MicroJobRegistryProperties microJobRegistryProperties; 54 | 55 | public MicroJobZookeeperRegistryAutoConfiguration(MicroJobRegistryProperties microJobRegistryProperties) { 56 | this.microJobRegistryProperties = microJobRegistryProperties; 57 | } 58 | 59 | /** 60 | * 实例注册中心 61 | * 62 | * @return 63 | */ 64 | @Bean 65 | @ConditionalOnMissingBean 66 | public InstanceRegistry instanceRegistry() { 67 | return new ZookeeperInstanceRegistry(microJobRegistryProperties.getZookeeper().getAddress(), microJobRegistryProperties.getZookeeper().getSessionTimeOut(), microJobRegistryProperties.getZookeeper().getConnectionTimeOut()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/registry/MicroJobRegistryProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.registry; 18 | 19 | import com.github.hengboy.job.core.enums.MicroJobRegistryAway; 20 | import lombok.Data; 21 | import lombok.Getter; 22 | import lombok.Setter; 23 | import org.springframework.boot.context.properties.ConfigurationProperties; 24 | 25 | import static com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties.REGISTRY_PROPERTIES_PREFIX; 26 | 27 | /** 28 | * 服务注册中心配置 29 | * 30 | * @author:恒宇少年 - 于起宇 31 | *

32 | * DateTime:2019-01-29 15:03 33 | * Blog:http://blog.yuqiyu.com 34 | * WebSite:http://www.jianshu.com/u/092df3f77bca 35 | * Gitee:https://gitee.com/hengboy 36 | * GitHub:https://github.com/hengyuboy 37 | */ 38 | @Data 39 | @ConfigurationProperties(prefix = REGISTRY_PROPERTIES_PREFIX) 40 | public class MicroJobRegistryProperties { 41 | /** 42 | * 注册中心配置前缀 43 | */ 44 | public final static String REGISTRY_PROPERTIES_PREFIX = "hengboy.job.registry"; 45 | /** 46 | * 任务注册中心部署的ip地址 47 | */ 48 | private String ipAddress = "127.0.0.1"; 49 | /** 50 | * 注册中心监听端口号 51 | * 默认端口号为:9000 52 | */ 53 | private int port = 9000; 54 | /** 55 | * 心跳同步执行间隔时间,单位:秒 56 | */ 57 | private int heartDelaySeconds = 5; 58 | /** 59 | * 注册中心注册方式 60 | * 默认内存方式 61 | */ 62 | private MicroJobRegistryAway away = MicroJobRegistryAway.MEMORY; 63 | /** 64 | * zookeeper 相关配置 65 | */ 66 | private ZookeeperProperties zookeeper = new ZookeeperProperties(); 67 | /** 68 | * consul 相关配置 69 | */ 70 | private ConsulProperties consul = new ConsulProperties(); 71 | 72 | /** 73 | * zookeeper属性配置 74 | */ 75 | @Getter 76 | @Setter 77 | class ZookeeperProperties { 78 | /** 79 | * zookeeper地址 80 | */ 81 | private String address = "127.0.0.1:2181"; 82 | /** 83 | * 会话超时时间 84 | */ 85 | private int sessionTimeOut = 100000; 86 | /** 87 | * 连接超时时间 88 | */ 89 | private int connectionTimeOut = 100000; 90 | } 91 | 92 | /** 93 | * consul 相关属性配置 94 | */ 95 | @Getter 96 | @Setter 97 | class ConsulProperties { 98 | /** 99 | * consul 地址 100 | */ 101 | private String address; 102 | /** 103 | * consul 端口号 104 | */ 105 | private int port; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/schedule/MicroJobScheduleProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.schedule; 18 | 19 | import lombok.Data; 20 | import org.springframework.boot.autoconfigure.quartz.JobStoreType; 21 | import org.springframework.boot.autoconfigure.quartz.QuartzProperties; 22 | import org.springframework.boot.context.properties.ConfigurationProperties; 23 | import org.springframework.boot.jdbc.DataSourceInitializationMode; 24 | 25 | /** 26 | * 分布式调度器属性相关配置 27 | * 28 | * @author:恒宇少年 - 于起宇 29 | *

30 | * DateTime:2019-01-28 10:33 31 | * Blog:http://blog.yuqiyu.com 32 | * WebSite:http://www.jianshu.com/u/092df3f77bca 33 | * Gitee:https://gitee.com/hengboy 34 | * GitHub:https://github.com/hengyuboy 35 | */ 36 | @Data 37 | @ConfigurationProperties(prefix = "hengboy.job.schedule") 38 | public class MicroJobScheduleProperties { 39 | /** 40 | * 最大重试次数 41 | */ 42 | private int maxRetryTimes = 2; 43 | /** 44 | * 调度器负载的权重 45 | */ 46 | private int loadBalanceWeight = 1; 47 | /** 48 | * 心跳同步执行间隔时间,单位:秒 49 | */ 50 | private int heartDelaySeconds = 5; 51 | /** 52 | * quartz Config Properties 53 | */ 54 | private MicroJobScheduleProperties.QuartzConfigProperties quartz; 55 | /** 56 | * 任务数据源类型,默认使用内存方式 57 | */ 58 | private JobStoreType jobStoreType = JobStoreType.MEMORY; 59 | 60 | /** 61 | * 如果并未自定义配置信息 62 | * 使用默认的配置信息 63 | * 64 | * @return 65 | */ 66 | public MicroJobScheduleProperties.QuartzConfigProperties getQuartz() { 67 | if (quartz == null) { 68 | // init 69 | quartz = new MicroJobScheduleProperties.QuartzConfigProperties(); 70 | 71 | // 设置任务存储方式为数据库方式 72 | quartz.setJobStoreType(jobStoreType); 73 | 74 | // 数据源方式,设置相关属性 75 | if (JobStoreType.JDBC.toString().equals(jobStoreType.toString())) { 76 | quartz.getJdbc().setInitializeSchema(DataSourceInitializationMode.EMBEDDED); 77 | quartz.getProperties().put("org.quartz.scheduler.instanceName", "jobScheduler"); 78 | quartz.getProperties().put("org.quartz.scheduler.instanceId", "AUTO"); 79 | quartz.getProperties().put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); 80 | quartz.getProperties().put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.StdJDBCDelegate"); 81 | quartz.getProperties().put("org.quartz.jobStore.tablePrefix", "MICRO_JOB_QRTZ_"); 82 | quartz.getProperties().put("org.quartz.jobStore.isClustered", "true"); 83 | quartz.getProperties().put("org.quartz.jobStore.clusterCheckinInterval", "20000"); 84 | quartz.getProperties().put("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true"); 85 | } 86 | } 87 | return quartz; 88 | } 89 | 90 | /** 91 | * quartz config 92 | */ 93 | @Data 94 | public static class QuartzConfigProperties extends QuartzProperties { 95 | public QuartzConfigProperties() { 96 | super(); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/provider/MicroJobProviderAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.provider; 18 | 19 | import com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties; 20 | import com.github.hengboy.job.core.http.MicroJobRestTemplate; 21 | import com.github.hengboy.job.provider.MicroJobProvider; 22 | import com.github.hengboy.job.provider.MicroJobProviderFactoryBean; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 25 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | 29 | /** 30 | * 任务生产者自动配置 31 | * 32 | * @author:恒宇少年 - 于起宇 33 | *

34 | * DateTime:2019-01-29 14:50 35 | * Blog:http://blog.yuqiyu.com 36 | * WebSite:http://www.jianshu.com/u/092df3f77bca 37 | * Gitee:https://gitee.com/hengboy 38 | * GitHub:https://github.com/hengyuboy 39 | */ 40 | @Configuration 41 | @ConditionalOnClass(MicroJobProviderFactoryBean.class) 42 | @EnableConfigurationProperties({MicroJobProviderProperties.class, MicroJobRegistryProperties.class}) 43 | public class MicroJobProviderAutoConfiguration { 44 | /** 45 | * 任务生产者配置注入 46 | */ 47 | MicroJobProviderProperties microJobProviderProperties; 48 | /** 49 | * 任务注册中心注入 50 | */ 51 | MicroJobRegistryProperties microJobRegistryProperties; 52 | 53 | /** 54 | * 构造函数初始化相关配置 55 | * 56 | * @param microJobProviderProperties 任务生产者 57 | * @param microJobRegistryProperties 任务注册中心 58 | */ 59 | public MicroJobProviderAutoConfiguration(MicroJobProviderProperties microJobProviderProperties, MicroJobRegistryProperties microJobRegistryProperties) { 60 | this.microJobProviderProperties = microJobProviderProperties; 61 | this.microJobRegistryProperties = microJobRegistryProperties; 62 | } 63 | 64 | /** 65 | * 实例化任务生产者对象 66 | * 设置注册中心方式、调度器调用负载均衡策略 67 | * 68 | * @return 69 | */ 70 | @Bean 71 | MicroJobProviderFactoryBean microJobProviderFactoryBean() { 72 | MicroJobProviderFactoryBean factoryBean = new MicroJobProviderFactoryBean(); 73 | factoryBean.setRegistryAway(microJobRegistryProperties.getAway()); 74 | factoryBean.setScheduleLbStrategy(microJobProviderProperties.getScheduleLbStrategy()); 75 | factoryBean.setSyncRegistryScheduleIntervalSeconds(microJobProviderProperties.getSyncRegistryScheduleIntervalSeconds()); 76 | factoryBean.setRegistryIpAddress(microJobRegistryProperties.getIpAddress()); 77 | factoryBean.setRegistryPort(microJobRegistryProperties.getPort()); 78 | return factoryBean; 79 | } 80 | 81 | /** 82 | * 任务操作生产者类实例化 83 | * 提供对任务的添加、删除、暂停、是否存在验证等方法 84 | * 每一个方法都是通过负载均衡策略进行远程调用 85 | * 86 | * @return 87 | */ 88 | @Bean 89 | MicroJobProvider microJobProvider() { 90 | return new MicroJobProvider(); 91 | } 92 | 93 | /** 94 | * 实例化restTemplate 95 | * 用于消费者、提供者、调度器、注册中心ws请求交互 96 | * 97 | * @return 98 | */ 99 | @Bean 100 | @ConditionalOnMissingBean 101 | public MicroJobRestTemplate restTemplate() { 102 | return new MicroJobRestTemplate(); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /micro-job-starters/spring-boot-starter-consumer/spring-boot-starter-consumer.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/consumer/MicroJobConsumerAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.consumer; 18 | 19 | import com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties; 20 | import com.github.hengboy.job.consumer.ConsumerFactoryBean; 21 | import com.github.hengboy.job.core.http.MicroJobRestTemplate; 22 | import com.github.hengboy.job.core.tools.JobSpringContext; 23 | import org.springframework.beans.factory.BeanFactory; 24 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 27 | import org.springframework.boot.autoconfigure.web.ServerProperties; 28 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 29 | import org.springframework.context.annotation.Bean; 30 | import org.springframework.context.annotation.Configuration; 31 | import org.springframework.util.StringUtils; 32 | 33 | /** 34 | * 任务消费者自动化配置 35 | * 36 | * @author:恒宇少年 - 于起宇 37 | *

38 | * DateTime:2019-01-30 15:26 39 | * Blog:http://blog.yuqiyu.com 40 | * WebSite:http://www.jianshu.com/u/092df3f77bca 41 | * Gitee:https://gitee.com/hengboy 42 | * GitHub:https://github.com/hengyuboy 43 | */ 44 | @Configuration 45 | @ConditionalOnClass(ConsumerFactoryBean.class) 46 | @EnableConfigurationProperties({MicroJobConsumerProperties.class, MicroJobRegistryProperties.class, ServerProperties.class}) 47 | public class MicroJobConsumerAutoConfiguration { 48 | /** 49 | * 任务消费者属性配置 50 | */ 51 | private MicroJobConsumerProperties microJobConsumerProperties; 52 | /** 53 | * 任务注册中心属性配置 54 | */ 55 | private MicroJobRegistryProperties microJobRegistryProperties; 56 | /** 57 | * 服务相关配置 58 | */ 59 | private ServerProperties serverProperties; 60 | /** 61 | * 注入spring bean factory 62 | * 用于获取springboot默认的package 63 | */ 64 | private BeanFactory beanFactory; 65 | 66 | /** 67 | * 构造函数自动实例化相关属性配置 68 | * 69 | * @param microJobConsumerProperties 任务消费者属性配置 70 | * @param microJobRegistryProperties 任务注册中心属性配置 71 | */ 72 | public MicroJobConsumerAutoConfiguration(MicroJobConsumerProperties microJobConsumerProperties, MicroJobRegistryProperties microJobRegistryProperties, ServerProperties serverProperties, BeanFactory beanFactory) { 73 | this.microJobConsumerProperties = microJobConsumerProperties; 74 | this.microJobRegistryProperties = microJobRegistryProperties; 75 | this.serverProperties = serverProperties; 76 | this.beanFactory = beanFactory; 77 | } 78 | 79 | /** 80 | * 实例化micro-job所需要操作spring ioc的类 81 | * 82 | * @return 83 | */ 84 | @Bean 85 | @ConditionalOnMissingBean 86 | JobSpringContext jobSpringContext() { 87 | return new JobSpringContext(); 88 | } 89 | 90 | /** 91 | * 实例化任务消费者工厂实例 92 | * - 注册中心配置信息 93 | * - 消费者配置信息 94 | * - 扫描microJob配置信息 95 | * 96 | * @return 97 | */ 98 | @Bean 99 | @ConditionalOnMissingBean 100 | public ConsumerFactoryBean consumerFactoryBean() { 101 | ConsumerFactoryBean factoryBean = new ConsumerFactoryBean(); 102 | 103 | // 设置注册中心配置信息 104 | factoryBean.setRegistryIpAddress(microJobRegistryProperties.getIpAddress()); 105 | factoryBean.setRegistryPort(microJobRegistryProperties.getPort()); 106 | 107 | factoryBean.setHeartDelaySeconds(microJobConsumerProperties.getHeartDelaySeconds()); 108 | factoryBean.setLoadBalanceWeight(microJobConsumerProperties.getLoadBalanceWeight()); 109 | 110 | // 设置端口号 111 | factoryBean.setListenPort(serverProperties.getPort()); 112 | 113 | // 使用配置文件配置的路径 114 | String scanMicroJobPackage = microJobConsumerProperties.getBaseScanMicroJobPackage(); 115 | // 如果并未配置,则使用springboot默认扫描的package 116 | if (StringUtils.isEmpty(scanMicroJobPackage)) { 117 | scanMicroJobPackage = AutoConfigurationPackages.get(beanFactory).get(0); 118 | } 119 | factoryBean.setJobScanBasePackage(scanMicroJobPackage); 120 | return factoryBean; 121 | } 122 | 123 | /** 124 | * 实例化restTemplate 125 | * 用于消费者、提供者、调度器、注册中心ws请求交互 126 | * 127 | * @return 128 | */ 129 | @Bean 130 | @ConditionalOnMissingBean 131 | public MicroJobRestTemplate restTemplate() { 132 | return new MicroJobRestTemplate(); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | pom 6 | 7 | micro-job-samples 8 | micro-job-autoconfigure 9 | micro-job-dependencies 10 | micro-job-starters 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.1.2.RELEASE 16 | 17 | 18 | com.github.hengboy 19 | spring-boot-micro-job 20 | 0.0.3.RELEASE 21 | spring-boot-micro-job 22 | 23 | spring-boot-micro-job 是一款分布式任务执行框架 24 | 核心组件: 25 | 1. 调度中心 26 | 2. 注册中心 27 | 3. 任务生产者 28 | 4. 任务消费者 29 | 30 | 31 | 32 | 1.8 33 | 34 | 0.0.3.RELEASE 35 | 36 | 37 | 38 | Yu Qi Yu 39 | yuqiyu@vip.qq.com 40 | github 41 | https://github.com/hengboy 42 | 43 | 44 | 45 | scm:git:https://github.com/hengboy/spring-boot-micro-job 46 | scm:git:https://github.com/hengboy/spring-boot-micro-job 47 | https://github.com/hengboy/spring-boot-micro-job 48 | 0.0.3.RELEASE 49 | 50 | 51 | 52 | Apache License, Version 2.0 53 | http://www.apache.org/licenses/LICENSE-2.0 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter 60 | 61 | 62 | 63 | 64 | hengyu 65 | https://oss.sonatype.org/content/repositories/snapshots 66 | 67 | 68 | hengyu 69 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 70 | 71 | 72 | 128 | 129 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/schedule/MicroJobScheduleAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.schedule; 18 | 19 | import com.github.hengboy.job.autoconfigure.registry.MicroJobRegistryProperties; 20 | import com.github.hengboy.job.core.http.MicroJobRestTemplate; 21 | import com.github.hengboy.job.schedule.ScheduleFactoryBean; 22 | import com.github.hengboy.job.schedule.store.DefaultJobStore; 23 | import com.github.hengboy.job.schedule.store.JobStore; 24 | import com.github.hengboy.job.schedule.store.customizer.JobStoreCustomizer; 25 | import org.quartz.Scheduler; 26 | import org.springframework.beans.factory.ObjectProvider; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 30 | import org.springframework.boot.autoconfigure.quartz.JobStoreType; 31 | import org.springframework.boot.autoconfigure.web.ServerProperties; 32 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 33 | import org.springframework.context.annotation.Bean; 34 | import org.springframework.context.annotation.Configuration; 35 | 36 | import javax.sql.DataSource; 37 | 38 | /** 39 | * 分布式调度器自动化配置 40 | * 41 | * @author:恒宇少年 - 于起宇 42 | *

43 | * DateTime:2019-01-28 10:37 44 | * Blog:http://blog.yuqiyu.com 45 | * WebSite:http://www.jianshu.com/u/092df3f77bca 46 | * Gitee:https://gitee.com/hengboy 47 | * GitHub:https://github.com/hengyuboy 48 | */ 49 | @Configuration 50 | @EnableConfigurationProperties({MicroJobScheduleProperties.class, MicroJobRegistryProperties.class, ServerProperties.class}) 51 | @ConditionalOnClass({Scheduler.class, ScheduleFactoryBean.class}) 52 | public class MicroJobScheduleAutoConfiguration { 53 | /** 54 | * 调度器属性配置 55 | */ 56 | private MicroJobScheduleProperties microJobScheduleProperties; 57 | /** 58 | * 任务注册中心属性配置 59 | */ 60 | private MicroJobRegistryProperties microJobRegistryProperties; 61 | /** 62 | * server属性配置 63 | */ 64 | private ServerProperties serverProperties; 65 | /** 66 | * 自定义jobStore配置 67 | */ 68 | private final ObjectProvider customizers; 69 | 70 | /** 71 | * 构造函数初始化注入对象信息 72 | * 73 | * @param microJobScheduleProperties 调度配置文件内容 74 | * @param customizers 自定义jobStore配置实现 75 | */ 76 | public MicroJobScheduleAutoConfiguration(MicroJobScheduleProperties microJobScheduleProperties, MicroJobRegistryProperties microJobRegistryProperties, ServerProperties serverProperties, ObjectProvider customizers) { 77 | this.microJobScheduleProperties = microJobScheduleProperties; 78 | this.microJobRegistryProperties = microJobRegistryProperties; 79 | this.serverProperties = serverProperties; 80 | this.customizers = customizers; 81 | } 82 | 83 | /** 84 | * 数据源自定义配置 85 | * 86 | * @param dataSource 数据源配置 87 | * @return 88 | */ 89 | @Bean 90 | @ConditionalOnBean(DataSource.class) 91 | JobStoreCustomizer dataSourceJobStoreCustomizer(DataSource dataSource) { 92 | return jobStore -> { 93 | DefaultJobStore defaultJobStore = (DefaultJobStore) jobStore; 94 | defaultJobStore.setDataSource(dataSource); 95 | }; 96 | } 97 | 98 | /** 99 | * 实例化任务数据源对象 100 | * 配置使用数据库方式 101 | * 102 | * @return 103 | */ 104 | @Bean 105 | JobStore jobStore() { 106 | // 默认任务数据源 107 | DefaultJobStore defaultJobStore = new DefaultJobStore(); 108 | 109 | // 数据库方式任务数据源 110 | if (JobStoreType.JDBC.toString().equals(microJobScheduleProperties.getJobStoreType().toString())) { 111 | defaultJobStore.setDelegateClassName("com.github.hengboy.job.schedule.store.delegate.JdbcSqlDelegate"); 112 | } 113 | 114 | // 如果存在自定义配置类 115 | this.customize(defaultJobStore); 116 | 117 | return defaultJobStore; 118 | } 119 | 120 | /** 121 | * 创建任务调度工厂对象 122 | * 123 | * @return 124 | */ 125 | @Bean 126 | ScheduleFactoryBean microJobScheduleFactoryBean() { 127 | ScheduleFactoryBean factoryBean = new ScheduleFactoryBean(); 128 | factoryBean.setHeartDelaySeconds(microJobScheduleProperties.getHeartDelaySeconds()); 129 | 130 | // 负载均衡权重 131 | factoryBean.setLoadBalanceWeight(microJobScheduleProperties.getLoadBalanceWeight()); 132 | factoryBean.setMaxRetryTimes(microJobScheduleProperties.getMaxRetryTimes()); 133 | 134 | // 设置任务注册中心配置信息 135 | factoryBean.setRegistryIpAddress(microJobRegistryProperties.getIpAddress()); 136 | factoryBean.setRegistryPort(microJobRegistryProperties.getPort()); 137 | 138 | // 设置端口号 139 | factoryBean.setPort(serverProperties.getPort()); 140 | 141 | return factoryBean; 142 | } 143 | 144 | 145 | /** 146 | * 任务数据源的自定义配置 147 | * 148 | * @param jobStore 任务数据源 149 | */ 150 | private void customize(JobStore jobStore) { 151 | this.customizers.orderedStream().forEach((customizer) -> customizer.customize(jobStore)); 152 | } 153 | 154 | /** 155 | * 实例化restTemplate 156 | * 用于消费者、提供者、调度器、注册中心ws请求交互 157 | * 158 | * @return 159 | */ 160 | @Bean 161 | @ConditionalOnMissingBean 162 | public MicroJobRestTemplate restTemplate() { 163 | return new MicroJobRestTemplate(); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-micro-job 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | 12 | 自动化配置依赖 13 | 1. 提供所有自动化属性注入定义 14 | 15 | micro-job-autoconfigure 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-configuration-processor 21 | 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | 27 | 28 | 29 | org.springframework 30 | spring-context-support 31 | true 32 | 33 | 34 | 35 | org.springframework 36 | spring-web 37 | true 38 | 39 | 40 | 41 | org.springframework 42 | spring-tx 43 | true 44 | 45 | 46 | 47 | org.quartz-scheduler 48 | quartz 49 | true 50 | 51 | 52 | 53 | com.github.hengboy 54 | micro-job-schedule 55 | true 56 | 57 | 58 | 59 | com.github.hengboy 60 | micro-job-provider 61 | true 62 | 63 | 64 | 65 | com.github.hengboy 66 | micro-job-consumer 67 | true 68 | 69 | 70 | 71 | com.github.hengboy 72 | micro-job-registry 73 | true 74 | 75 | 76 | 77 | com.github.hengboy 78 | micro-job-registry-memory 79 | true 80 | 81 | 82 | 83 | org.springframework.boot 84 | spring-boot-starter-data-redis 85 | true 86 | 87 | 88 | 89 | com.github.hengboy 90 | micro-job-registry-redis 91 | true 92 | 93 | 94 | 95 | com.101tec 96 | zkclient 97 | true 98 | 99 | 100 | 101 | com.github.hengboy 102 | micro-job-registry-zookeeper 103 | true 104 | 105 | 106 | 107 | com.orbitz.consul 108 | consul-client 109 | true 110 | 111 | 112 | 113 | com.github.hengboy 114 | micro-job-registry-consul 115 | true 116 | 117 | 118 | 119 | 120 | com.github.hengboy 121 | micro-job-registry-nacos 122 | true 123 | 124 | 125 | 126 | com.alibaba.boot 127 | nacos-discovery-spring-boot-starter 128 | true 129 | 130 | 131 | com.alibaba.nacos 132 | nacos-client 133 | 134 | 135 | 136 | 137 | com.alibaba.nacos 138 | nacos-client 139 | 0.8.2 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | com.github.hengboy 149 | micro-job-dependencies 150 | ${micro.job.dependencies.version} 151 | pom 152 | import 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | ![](http://job.yuqiyu.com/svgs/logo.svg) 2 | 3 | [![Build Status](https://travis-ci.org/hengboy/spring-boot-micro-job.svg?branch=master)](https://travis-ci.org/hengboy/spring-boot-micro-job)[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://github.com/weibocom/motan/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/com.github.hengboy/spring-boot-starter.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.hengboy%22%20AND%20a:%22spring-boot-starter%22) ![](https://img.shields.io/badge/JDK-1.8+-green.svg) ![](https://img.shields.io/badge/SpringBoot-1.4+_1.5+_2.0+-green.svg) [![](http://job.yuqiyu.com/svgs/english.svg)](README.md) 4 | 5 | `micro-job`是一款`分布式任务调度执行框架`,内部通过各个组件的`Jersey`共享出的`Rest`路径进行数据访问。 6 | 7 | 详细开发文档 [访问官网](http://job.yuqiyu.com/#/) 8 | 9 | ![](http://job.yuqiyu.com/resource/image/MicroJob%20%E4%BA%A4%E6%B5%81%E2%91%A0%E7%BE%A4%E7%BE%A4%E4%BA%8C%E7%BB%B4%E7%A0%81.png) 10 | > 名词解释: 11 | > 12 | > `consumer` -> `任务消费节点` 13 | > 14 | > `schedule` -> `任务调度器` 15 | > 16 | > `provider` -> `任务生产者` 17 | > 18 | > `registry` -> `任务注册中心` 19 | 20 | ## 任务注册中心(registry) 21 | 22 | `registry`是任务注册中心,在整个生态圈内担任着各个组件注册节点的任务,任务注册中心实现方式是多样化的,目前包含:`memory`、`zookeeper`、`redis`、`consul`等。 23 | 24 | 通过`idea、eclipse`工具创建`SpringBoot`项目并添加如下依赖到`pom.xml`文件内。 25 | 26 | ``` 27 | 28 | com.github.hengboy 29 | spring-boot-starter-registry-memory 30 | {lastVersion} 31 | 32 | ``` 33 | 34 | 在`resources`资源目录下添加`application.yml`配置文件,配置内容如下所示: 35 | 36 | ```yaml 37 | server: 38 | port: 9000 39 | hengboy: 40 | job: 41 | registry: 42 | # 任务注册中心节点注册方式 43 | away: memory 44 | ``` 45 | 46 | 47 | 48 | ## 任务调度器(schedule) 49 | 50 | `schedule`是任务调度器,每一个任务的创建都是通过调度器进行分配执行,分配过程中根据消费节点的负载均衡策略配置进行不同消费者节点任务消费。 51 | 52 | 在生产任务时,也会根据调度器的`负载均衡策略`来进行筛选执行任务调度的`调度器节点`。 53 | 54 | 通过`idea、eclipse`工具创建`SpringBoot`项目并添加如下依赖到`pom.xml`文件内。 55 | 56 | ```xml 57 | 58 | com.github.hengboy 59 | spring-boot-starter-schedule 60 | {lastVersion} 61 | 62 | ``` 63 | 64 | 在`resources`资源目录下添加`application.yml`配置文件,配置内容如下所示: 65 | 66 | ```yaml 67 | server: 68 | port: 8081 69 | hengboy: 70 | job: 71 | registry: 72 | # 保持与任务注册中心节点注册方式一致即可 73 | away: memory 74 | schedule: 75 | # 内存方式调度器处理任务队列以及任务日志的存储 76 | job-store-type: memory 77 | ``` 78 | 79 | 80 | 81 | ## 任务消费节点(consumer) 82 | 83 | `consumer`是任务消费者执行节点,任务由`consumer`进行定义以及上报,当`schedule`调用消费者执行任务请求时,会自动根据`jobKey`来执行对应的任务逻辑方法。 84 | 85 | 通过`idea、eclipse`工具创建`SpringBoot`项目并添加如下依赖到`pom.xml`文件内。 86 | 87 | ```xml 88 | 89 | com.github.hengboy 90 | spring-boot-starter-consumer 91 | {lastVersion} 92 | 93 | ``` 94 | 95 | 在`resources`资源目录下添加`application.yml`配置文件,配置内容如下所示: 96 | 97 | ```yaml 98 | server: 99 | port: 8082 100 | hengboy: 101 | job: 102 | registry: 103 | # 保持与任务注册中心节点注册方式一致即可 104 | away: memory 105 | ``` 106 | 107 | ### 任务定义示例 108 | 109 | 我们来定义一个简单的`Job`,示例如下所示: 110 | 111 | ```j 112 | @Job(jobExecuteAway = JobExecuteAwayEnum.ONCE) 113 | public class TestJob implements MicroJob { 114 | /** 115 | * logger instance 116 | */ 117 | static Logger logger = LoggerFactory.getLogger(TestJob.class); 118 | 119 | @Override 120 | public JobExecuteResult execute(JobExecuteParam jobExecuteParam) throws JobException { 121 | logger.info("执行Key:{},执行参数:{}", jobExecuteParam.getJobKey(), jobExecuteParam.getJsonParam()); 122 | return JobExecuteResult.JOB_EXECUTE_SUCCESS; 123 | } 124 | } 125 | ``` 126 | 127 | > 在上面定义的`Job`对应的`JobKey`为`testJob`. 128 | 129 | 130 | 131 | ## 任务生产节点(provider) 132 | 133 | `provider`是任务生产节点,由业务方进行添加依赖并执行`MicroJobProvider.newXxxJob`调用创建任务,如:`创建订单后`执行`发送邮件`通知操作。 134 | 135 | 通过`idea、eclipse`工具创建`SpringBoot`项目并添加如下依赖到`pom.xml`文件内。 136 | 137 | ```xml 138 | 139 | com.github.hengboy 140 | spring-boot-starter-provider 141 | {lastVersion} 142 | 143 | ``` 144 | 145 | 在`resources`资源目录下添加`application.yml`配置文件,配置内容如下所示: 146 | 147 | ```yaml 148 | server: 149 | port: 8083 150 | hengboy: 151 | job: 152 | registry: 153 | # 保持与任务注册中心节点注册方式一致即可 154 | away: memory 155 | ``` 156 | 157 | ### 任务执行示例 158 | 159 | ```java 160 | @RunWith(SpringRunner.class) 161 | @SpringBootTest 162 | public class ProviderTester { 163 | /** 164 | * 注册任务提供者 165 | */ 166 | @Autowired 167 | private MicroJobProvider microJobProvider; 168 | 169 | @Test 170 | public void newJob() { 171 | // 创建的任务仅执行一次 172 | microJobProvider.newOnceJob(OnceJobWrapper.Context() 173 | // 对应consumer内定义任务的jobKey,默认为类名首字母小写 174 | .jobKey("testJob") 175 | // 自定义的任务队列key,可以准确定位任务并操作暂停、删除等操作 176 | .jobQueueKey(UUID.randomUUID().toString()) 177 | // 参数,任意类型参数,consumer消费时会转换为json字符串 178 | .param(new HashMap() { 179 | { 180 | put("name", "admin"); 181 | } 182 | }) 183 | .wrapper()); 184 | } 185 | } 186 | ``` 187 | 188 | 189 | 190 | ## 测试流程 191 | 192 | > 1. 启动任务注册中心 193 | > 2. 启动任务调度中心 194 | > 3. 启动任务消费者节点 195 | > 4. 执行ProviderTester#newJob单元测试方法 196 | 197 | ## Folders 198 | 199 | ``` 200 | ​``` 201 | . 202 | ├── micro-job-autoconfigure 203 | ├── micro-job-dependencies 204 | ├── micro-job-samples 205 | │ ├── sample-consumer 206 | │ ├── sample-provider 207 | │ ├── sample-registry-consul 208 | │ ├── sample-registry-memory 209 | │ ├── sample-registry-redis 210 | │ ├── sample-registry-zookeeper 211 | │ ├── sample-schedule 212 | │ ├── pom.xml 213 | │ └── README.md 214 | ├── micro-job-starters 215 | │ ├── spring-boot-starter 216 | │ ├── spring-boot-starter-provider 217 | │ ├── spring-boot-starter-registry-consul 218 | │ ├── spring-boot-starter-registry-memory 219 | │ ├── spring-boot-starter-registry-redis 220 | │ ├── spring-boot-starter-registry-zookeeper 221 | │ ├── spring-boot-starter-schedule 222 | │ └── pom.xml 223 | ├── .travis.yml 224 | ├── LICENSE 225 | ├── pom.xml 226 | └── README.md 227 | ​``` 228 | ``` 229 | 230 | ## License 231 | 232 | The Apache License 233 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](http://job.yuqiyu.com/svgs/logo.svg) 2 | 3 | [![Build Status](https://travis-ci.org/hengboy/spring-boot-micro-job.svg?branch=master)](https://travis-ci.org/hengboy/spring-boot-micro-job)[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://github.com/weibocom/motan/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/com.github.hengboy/spring-boot-starter.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.hengboy%22%20AND%20a:%22spring-boot-starter%22) ![](https://img.shields.io/badge/JDK-1.8+-green.svg) ![](https://img.shields.io/badge/SpringBoot-1.4+_1.5+_2.0+-green.svg) [![](http://job.yuqiyu.com/svgs/chinese.svg)](README_zh.md) 4 | 5 | `Micro-job` is a distributed task scheduling and execution framework, which accesses data internally through the Rest path shared by `Jersey` of each component. 6 | 7 | Detailed development documentation [Visit official website](http://job.yuqiyu.com/#/) 8 | 9 | > Noun interpretation: 10 | > 11 | > `consumer` -> `Task Consumption Node` 12 | > 13 | > `schedule` -> `Task Scheduler` 14 | > 15 | > `provider` -> `Task Producer` 16 | > 17 | > `registry` -> `Task Registry` 18 | 19 | ## Registry 20 | 21 | ` Regisry `serves as the task of registering nodes of each component in the whole ecosystem. The way to implement the task registry is diversified. At present, it includes `memory', `zookeeper', `redis', `consul', etc. 22 | 23 | Create the `SpringBoot'project through idea and eclipse tools and add the following dependencies to the `pom.xml' file. 24 | 25 | ``` 26 | 27 | com.github.hengboy 28 | spring-boot-starter-registry-memory 29 | {lastVersion} 30 | 31 | ``` 32 | 33 | Add the `application.yml'configuration file to the `resources' resource directory as follows: 34 | 35 | ```yaml 36 | server: 37 | port: 9000 38 | hengboy: 39 | job: 40 | registry: 41 | # ask Registry Node Registration 42 | away: memory 43 | ``` 44 | 45 | 46 | 47 | ## Schedule 48 | 49 | Each task is created through a dispatcher to allocate and execute. In the process of allocation, different tasks are consumed by different consumer nodes according to the load balancing strategy configuration of the consumer nodes. 50 | In production tasks, the `scheduler nodes'that perform task scheduling are also filtered according to the `load balancing strategy' of the scheduler. 51 | Create `SpringBoot'project through `idea' and `eclipse'tools and add the following dependencies to the `pom.xml' file. 52 | 53 | ```xml 54 | 55 | com.github.hengboy 56 | spring-boot-starter-schedule 57 | {lastVersion} 58 | 59 | ``` 60 | 61 | Add the `application.yml'configuration file to the `resources' resource directory as follows: 62 | 63 | ```yaml 64 | server: 65 | port: 8081 66 | hengboy: 67 | job: 68 | registry: 69 | # Maintain consistency with task registry node registration 70 | away: memory 71 | schedule: 72 | # Memory Scheduler handles task queues and storage of task logs 73 | job-store-type: memory 74 | ``` 75 | 76 | 77 | 78 | ## Consumer 79 | 80 | Tasks are defined and reported by `consumer'. When `schedule'invokes a consumer to execute a task request, the corresponding task logic method is automatically executed according to `jobKey'. 81 | Create `SpringBoot'project through `idea' and `eclipse'tools and add the following dependencies to the `pom.xml' file. 82 | 83 | ```xml 84 | 85 | com.github.hengboy 86 | spring-boot-starter-consumer 87 | {lastVersion} 88 | 89 | ``` 90 | 91 | Add the `application.yml'configuration file to the `resources' resource directory as follows: 92 | 93 | ```yaml 94 | server: 95 | port: 8082 96 | hengboy: 97 | job: 98 | registry: 99 | # Maintain consistency with task registry node registration 100 | away: memory 101 | ``` 102 | 103 | ### Example Of JOB Definition 104 | 105 | Let's define a simple `Job', as follows: 106 | 107 | ```j 108 | @Job(jobExecuteAway = JobExecuteAwayEnum.ONCE) 109 | public class TestJob implements MicroJob { 110 | /** 111 | * logger instance 112 | */ 113 | static Logger logger = LoggerFactory.getLogger(TestJob.class); 114 | 115 | @Override 116 | public JobExecuteResult execute(JobExecuteParam jobExecuteParam) throws JobException { 117 | logger.info("Key:{},Param:{}", jobExecuteParam.getJobKey(), jobExecuteParam.getJsonParam()); 118 | return JobExecuteResult.JOB_EXECUTE_SUCCESS; 119 | } 120 | } 121 | ``` 122 | 123 | > The `Job', as defined above, corresponds to `JobKey', which is `testJob'. 124 | 125 | 126 | 127 | ## Provider 128 | 129 | The business side adds dependencies and performs `MicroJobProvider. newXxxJob'call creation tasks, such as `Send mail' notification operation after creating an order'. 130 | Create `SpringBoot'project through `idea' and `eclipse'tools and add the following dependencies to the `pom.xml' file. 131 | 132 | ```xml 133 | 134 | com.github.hengboy 135 | spring-boot-starter-provider 136 | {lastVersion} 137 | 138 | ``` 139 | 140 | Add the `application.yml'configuration file to the `resources' resource directory as follows: 141 | 142 | ```yaml 143 | server: 144 | port: 8083 145 | hengboy: 146 | job: 147 | registry: 148 | # Maintain consistency with task registry node registration 149 | away: memory 150 | ``` 151 | 152 | ### JOB Execution Example 153 | 154 | ```java 155 | @RunWith(SpringRunner.class) 156 | @SpringBootTest 157 | public class ProviderTester { 158 | /** 159 | * Registered Task Provider 160 | */ 161 | @Autowired 162 | private MicroJobProvider microJobProvider; 163 | 164 | @Test 165 | public void newJob() { 166 | // Created tasks are executed only once 167 | microJobProvider.newOnceJob(OnceJobWrapper.Context() 168 | // JobKey, which corresponds to tasks defined in consumer, defaults to lowercase class names 169 | .jobKey("testJob") 170 | // Customized task queue key, can accurately locate tasks and operate pause, delete and other operations 171 | .jobQueueKey(UUID.randomUUID().toString()) 172 | // Parameters, parameters of any type, when consumer consumes, are converted to JSON strings 173 | .param(new HashMap() { 174 | { 175 | put("name", "admin"); 176 | } 177 | }) 178 | .wrapper()); 179 | } 180 | } 181 | ``` 182 | 183 | 184 | 185 | ## Test flow 186 | 187 | > 1. Start Task Registry 188 | > 2. Start Task Scheduling Center 189 | > 3. Start Task Consumer Node 190 | > 4. Execute the Provider Tester # newJob unit test method 191 | 192 | ## Folders 193 | 194 | ``` 195 | ​``` 196 | . 197 | ├── micro-job-autoconfigure 198 | ├── micro-job-dependencies 199 | ├── micro-job-samples 200 | │ ├── sample-consumer 201 | │ ├── sample-provider 202 | │ ├── sample-registry-consul 203 | │ ├── sample-registry-memory 204 | │ ├── sample-registry-redis 205 | │ ├── sample-registry-zookeeper 206 | │ ├── sample-schedule 207 | │ ├── pom.xml 208 | │ └── README.md 209 | ├── micro-job-starters 210 | │ ├── spring-boot-starter 211 | │ ├── spring-boot-starter-provider 212 | │ ├── spring-boot-starter-registry-consul 213 | │ ├── spring-boot-starter-registry-memory 214 | │ ├── spring-boot-starter-registry-redis 215 | │ ├── spring-boot-starter-registry-zookeeper 216 | │ ├── spring-boot-starter-schedule 217 | │ └── pom.xml 218 | ├── .travis.yml 219 | ├── LICENSE 220 | ├── pom.xml 221 | └── README.md 222 | ​``` 223 | ``` 224 | 225 | ## License 226 | 227 | The Apache License 228 | -------------------------------------------------------------------------------- /micro-job-autoconfigure/src/main/java/com/github/hengboy/job/autoconfigure/schedule/MicroJobQuartzAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright [2019] [恒宇少年 - 于起宇] 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.hengboy.job.autoconfigure.schedule; 18 | 19 | import com.github.hengboy.job.schedule.ScheduleFactoryBean; 20 | import org.quartz.Calendar; 21 | import org.quartz.JobDetail; 22 | import org.quartz.Scheduler; 23 | import org.quartz.Trigger; 24 | import org.springframework.beans.factory.ObjectProvider; 25 | import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor; 26 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 29 | import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; 30 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 31 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 32 | import org.springframework.boot.autoconfigure.quartz.*; 33 | import org.springframework.boot.autoconfigure.transaction.PlatformTransactionManagerCustomizer; 34 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 35 | import org.springframework.context.ApplicationContext; 36 | import org.springframework.context.annotation.Bean; 37 | import org.springframework.context.annotation.Configuration; 38 | import org.springframework.core.annotation.Order; 39 | import org.springframework.core.io.ResourceLoader; 40 | import org.springframework.scheduling.quartz.SchedulerFactoryBean; 41 | import org.springframework.scheduling.quartz.SpringBeanJobFactory; 42 | import org.springframework.transaction.PlatformTransactionManager; 43 | 44 | import javax.sql.DataSource; 45 | import java.util.Map; 46 | import java.util.Properties; 47 | 48 | /** 49 | * @author:恒宇少年 - 于起宇 50 | *

51 | * DateTime:2019-01-31 11:34 52 | * Blog:http://blog.yuqiyu.com 53 | * WebSite:http://www.jianshu.com/u/092df3f77bca 54 | * Gitee:https://gitee.com/hengboy 55 | * GitHub:https://github.com/hengyuboy 56 | */ 57 | @Configuration 58 | @ConditionalOnClass({Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManagerCustomizer.class, ScheduleFactoryBean.class}) 59 | @EnableConfigurationProperties({QuartzProperties.class, MicroJobScheduleProperties.class}) 60 | @AutoConfigureAfter({DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 61 | public class MicroJobQuartzAutoConfiguration { 62 | private final QuartzProperties properties; 63 | private final MicroJobScheduleProperties microJobScheduleProperties; 64 | private final ObjectProvider customizers; 65 | private final JobDetail[] jobDetails; 66 | private final Map calendars; 67 | private final Trigger[] triggers; 68 | private final ApplicationContext applicationContext; 69 | 70 | public MicroJobQuartzAutoConfiguration(QuartzProperties properties, MicroJobScheduleProperties microJobScheduleProperties, ObjectProvider customizers, ObjectProvider jobDetails, ObjectProvider> calendars, ObjectProvider triggers, ApplicationContext applicationContext) { 71 | this.properties = properties; 72 | this.microJobScheduleProperties = microJobScheduleProperties; 73 | this.customizers = customizers; 74 | this.jobDetails = (JobDetail[]) jobDetails.getIfAvailable(); 75 | this.calendars = (Map) calendars.getIfAvailable(); 76 | this.triggers = (Trigger[]) triggers.getIfAvailable(); 77 | this.applicationContext = applicationContext; 78 | // 初始化job属性配置信息 79 | initJobProperties(this.properties); 80 | } 81 | 82 | @Bean 83 | @ConditionalOnMissingBean 84 | public SchedulerFactoryBean quartzScheduler() { 85 | SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); 86 | SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); 87 | jobFactory.setApplicationContext(this.applicationContext); 88 | schedulerFactoryBean.setJobFactory(jobFactory); 89 | if (this.properties.getSchedulerName() != null) { 90 | schedulerFactoryBean.setSchedulerName(this.properties.getSchedulerName()); 91 | } 92 | 93 | schedulerFactoryBean.setAutoStartup(this.properties.isAutoStartup()); 94 | schedulerFactoryBean.setStartupDelay((int) this.properties.getStartupDelay().getSeconds()); 95 | schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(this.properties.isWaitForJobsToCompleteOnShutdown()); 96 | schedulerFactoryBean.setOverwriteExistingJobs(this.properties.isOverwriteExistingJobs()); 97 | if (!this.properties.getProperties().isEmpty()) { 98 | schedulerFactoryBean.setQuartzProperties(this.asProperties(this.properties.getProperties())); 99 | } 100 | 101 | if (this.jobDetails != null && this.jobDetails.length > 0) { 102 | schedulerFactoryBean.setJobDetails(this.jobDetails); 103 | } 104 | 105 | if (this.calendars != null && !this.calendars.isEmpty()) { 106 | schedulerFactoryBean.setCalendars(this.calendars); 107 | } 108 | 109 | if (this.triggers != null && this.triggers.length > 0) { 110 | schedulerFactoryBean.setTriggers(this.triggers); 111 | } 112 | 113 | this.customize(schedulerFactoryBean); 114 | return schedulerFactoryBean; 115 | } 116 | 117 | private Properties asProperties(Map source) { 118 | Properties properties = new Properties(); 119 | properties.putAll(source); 120 | return properties; 121 | } 122 | 123 | private void customize(SchedulerFactoryBean schedulerFactoryBean) { 124 | this.customizers.orderedStream().forEach((customizer) -> { 125 | customizer.customize(schedulerFactoryBean); 126 | }); 127 | } 128 | 129 | @Configuration 130 | @ConditionalOnSingleCandidate(DataSource.class) 131 | protected static class JdbcStoreTypeConfiguration { 132 | protected JdbcStoreTypeConfiguration() { 133 | } 134 | 135 | @Bean 136 | @Order(0) 137 | public SchedulerFactoryBeanCustomizer jobDataSourceCustomizer(QuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider quartzDataSource, ObjectProvider transactionManager) { 138 | return (schedulerFactoryBean) -> { 139 | if (properties.getJobStoreType() == JobStoreType.JDBC) { 140 | DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource); 141 | schedulerFactoryBean.setDataSource(dataSourceToUse); 142 | PlatformTransactionManager txManager = (PlatformTransactionManager) transactionManager.getIfUnique(); 143 | if (txManager != null) { 144 | schedulerFactoryBean.setTransactionManager(txManager); 145 | } 146 | } 147 | 148 | }; 149 | } 150 | 151 | private DataSource getDataSource(DataSource dataSource, ObjectProvider quartzDataSource) { 152 | DataSource dataSourceIfAvailable = (DataSource) quartzDataSource.getIfAvailable(); 153 | return dataSourceIfAvailable != null ? dataSourceIfAvailable : dataSource; 154 | } 155 | 156 | @Bean 157 | @ConditionalOnMissingBean 158 | public QuartzDataSourceInitializer quartzDataSourceInitializer(DataSource dataSource, @QuartzDataSource ObjectProvider quartzDataSource, ResourceLoader resourceLoader, QuartzProperties properties) { 159 | DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource); 160 | return new QuartzDataSourceInitializer(dataSourceToUse, resourceLoader, properties); 161 | } 162 | 163 | @Bean 164 | public static MicroJobQuartzAutoConfiguration.JdbcStoreTypeConfiguration.DataSourceInitializerSchedulerDependencyPostProcessor jobDataSourceInitializerSchedulerDependencyPostProcessor() { 165 | return new MicroJobQuartzAutoConfiguration.JdbcStoreTypeConfiguration.DataSourceInitializerSchedulerDependencyPostProcessor(); 166 | } 167 | 168 | private static class DataSourceInitializerSchedulerDependencyPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor { 169 | DataSourceInitializerSchedulerDependencyPostProcessor() { 170 | super(Scheduler.class, SchedulerFactoryBean.class, new String[]{"quartzDataSourceInitializer"}); 171 | } 172 | } 173 | } 174 | 175 | /** 176 | * 初始化任务属性配置 177 | * 178 | * @param quartzProperties quartz属性配置 179 | */ 180 | private void initJobProperties(QuartzProperties quartzProperties) { 181 | // 设置任务存储方式为数据库方式 182 | quartzProperties.setJobStoreType(microJobScheduleProperties.getQuartz().getJobStoreType()); 183 | 184 | // 设置schema初始化模式 185 | quartzProperties.getJdbc().setInitializeSchema(microJobScheduleProperties.getQuartz().getJdbc().getInitializeSchema()); 186 | 187 | // 设置属性配置 188 | quartzProperties.getProperties().putAll(microJobScheduleProperties.getQuartz().getProperties()); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /micro-job-dependencies/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-micro-job 7 | com.github.hengboy 8 | 0.0.3.RELEASE 9 | 10 | 4.0.0 11 | micro-job-dependencies 12 | 13 | 14 | 0.0.3.RELEASE 15 | 0.0.3.RELEASE 16 | 0.0.3.RELEASE 17 | 0.0.3.RELEASE 18 | 0.0.3.RELEASE 19 | 0.0.3.RELEASE 20 | 0.0.3.RELEASE 21 | 0.0.3.RELEASE 22 | 2.3.0 23 | 5.1.4.RELEASE 24 | 5.1.4.RELEASE 25 | 5.1.4.RELEASE 26 | 0.0.3.RELEASE 27 | 1.18.4 28 | 0.0.3.RELEASE 29 | 0.0.3.RELEASE 30 | 0.0.3.RELEASE 31 | 0.0.3.RELEASE 32 | 0.0.3.RELEASE 33 | 0.0.3.RELEASE 34 | 0.0.3.RELEASE 35 | 0.0.3.RELEASE 36 | 0.0.3.RELEASE 37 | 0.2.1 38 | 0.11 39 | 1.3.1 40 | 41 | 42 | 43 | 44 | 45 | 46 | com.github.hengboy 47 | spring-boot-starter 48 | ${micro.job.starter.version} 49 | 50 | 51 | 52 | com.github.hengboy 53 | spring-boot-starter-consumer 54 | ${micro.job.consumer.version} 55 | 56 | 57 | 58 | com.github.hengboy 59 | spring-boot-starter-provider 60 | ${micro.job.provider.version} 61 | 62 | 63 | 64 | com.github.hengboy 65 | spring-boot-starter-schedule 66 | ${micro.job.schedule.version} 67 | 68 | 69 | 70 | com.github.hengboy 71 | spring-boot-starter-registry-memory 72 | ${micro.job.registry.memory.version} 73 | 74 | 75 | 76 | com.github.hengboy 77 | spring-boot-starter-registry-consul 78 | ${micro.job.registry.consul.version} 79 | 80 | 81 | 82 | com.github.hengboy 83 | spring-boot-starter-registry-redis 84 | ${micro.job.registry.redis.version} 85 | 86 | 87 | 88 | com.github.hengboy 89 | spring-boot-starter-registry-zookeeper 90 | ${micro.job.registry.zookeeper.version} 91 | 92 | 93 | 94 | org.quartz-scheduler 95 | quartz 96 | ${quartz.schedule.version} 97 | 98 | 99 | 100 | org.springframework 101 | spring-context-support 102 | ${spring.context.version} 103 | 104 | 105 | 106 | org.springframework 107 | spring-web 108 | ${spring.web.version} 109 | 110 | 111 | 112 | org.springframework 113 | spring-tx 114 | ${spring.tx.version} 115 | 116 | 117 | 118 | com.github.hengboy 119 | micro-job-autoconfigure 120 | ${micro.job.autoconfigure.version} 121 | 122 | 123 | 124 | org.projectlombok 125 | lombok 126 | ${lombok.version} 127 | 128 | 129 | 130 | 131 | com.github.hengboy 132 | micro-job-schedule 133 | ${micro.schedule.version} 134 | 135 | 136 | 137 | com.github.hengboy 138 | micro-job-provider 139 | ${micro.provider.version} 140 | 141 | 142 | 143 | com.github.hengboy 144 | micro-job-consumer 145 | ${micro.consumer.version} 146 | 147 | 148 | 149 | com.github.hengboy 150 | micro-job-registry 151 | ${micro.registry.version} 152 | 153 | 154 | 155 | com.github.hengboy 156 | micro-job-registry-memory 157 | ${micro.registry.memory.version} 158 | 159 | 160 | 161 | com.github.hengboy 162 | micro-job-registry-redis 163 | ${micro.registry.redis.version} 164 | 165 | 166 | 167 | com.101tec 168 | zkclient 169 | ${zkclient.version} 170 | 171 | 172 | 173 | com.github.hengboy 174 | micro-job-registry-zookeeper 175 | ${micro.registry.zookeeper.version} 176 | 177 | 178 | 179 | com.orbitz.consul 180 | consul-client 181 | ${consul.client.version} 182 | 183 | 184 | 185 | com.github.hengboy 186 | micro-job-registry-consul 187 | ${micro.registry.consul.version} 188 | 189 | 190 | com.github.hengboy 191 | micro-job-registry-nacos 192 | ${micro.registry.nacos.version} 193 | 194 | 195 | 196 | com.alibaba.boot 197 | nacos-discovery-spring-boot-starter 198 | ${nacos.discovery.spring.boot.version} 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------