├── .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 | 
2 |
3 | [](https://travis-ci.org/hengboy/spring-boot-micro-job)[](https://github.com/weibocom/motan/blob/master/LICENSE) [](https://search.maven.org/search?q=g:%22com.github.hengboy%22%20AND%20a:%22spring-boot-starter%22)   [](README.md)
4 |
5 | `micro-job`是一款`分布式任务调度执行框架`,内部通过各个组件的`Jersey`共享出的`Rest`路径进行数据访问。
6 |
7 | 详细开发文档 [访问官网](http://job.yuqiyu.com/#/)
8 |
9 | 
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 | 
2 |
3 | [](https://travis-ci.org/hengboy/spring-boot-micro-job)[](https://github.com/weibocom/motan/blob/master/LICENSE) [](https://search.maven.org/search?q=g:%22com.github.hengboy%22%20AND%20a:%22spring-boot-starter%22)   [](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