com.github.hengboy:micro-job-autoconfigure

自动化配置依赖 1. 提供所有自动化属性注入定义

License

License

Categories

Categories

Auto Application Layer Libs Code Generators config Configuration
GroupId

GroupId

com.github.hengboy
ArtifactId

ArtifactId

micro-job-autoconfigure
Last Version

Last Version

0.0.3.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

自动化配置依赖 1. 提供所有自动化属性注入定义
Project URL

Project URL

https://projects.spring.io/spring-boot/#/spring-boot-starter-parent/micro-job-autoconfigure

Download micro-job-autoconfigure

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.hengboy/micro-job-autoconfigure/ -->
<dependency>
    <groupId>com.github.hengboy</groupId>
    <artifactId>micro-job-autoconfigure</artifactId>
    <version>0.0.3.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.hengboy/micro-job-autoconfigure/
implementation 'com.github.hengboy:micro-job-autoconfigure:0.0.3.RELEASE'
// https://jarcasting.com/artifacts/com.github.hengboy/micro-job-autoconfigure/
implementation ("com.github.hengboy:micro-job-autoconfigure:0.0.3.RELEASE")
'com.github.hengboy:micro-job-autoconfigure:jar:0.0.3.RELEASE'
<dependency org="com.github.hengboy" name="micro-job-autoconfigure" rev="0.0.3.RELEASE">
  <artifact name="micro-job-autoconfigure" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.hengboy', module='micro-job-autoconfigure', version='0.0.3.RELEASE')
)
libraryDependencies += "com.github.hengboy" % "micro-job-autoconfigure" % "0.0.3.RELEASE"
[com.github.hengboy/micro-job-autoconfigure "0.0.3.RELEASE"]

Dependencies

compile (21)

Group / Artifact Type Version
org.springframework.boot : spring-boot-configuration-processor jar 2.1.2.RELEASE
org.projectlombok : lombok jar 1.18.4
org.springframework : spring-context-support Optional jar
org.springframework : spring-web Optional jar
org.springframework : spring-tx Optional jar
org.quartz-scheduler : quartz Optional jar 2.3.0
com.github.hengboy : micro-job-schedule Optional jar
com.github.hengboy : micro-job-provider Optional jar
com.github.hengboy : micro-job-consumer Optional jar
com.github.hengboy : micro-job-registry Optional jar
com.github.hengboy : micro-job-registry-memory Optional jar
org.springframework.boot : spring-boot-starter-data-redis Optional jar 2.1.2.RELEASE
com.github.hengboy : micro-job-registry-redis Optional jar
com.101tec : zkclient Optional jar
com.github.hengboy : micro-job-registry-zookeeper Optional jar
com.orbitz.consul : consul-client Optional jar
com.github.hengboy : micro-job-registry-consul Optional jar
com.github.hengboy : micro-job-registry-nacos Optional jar
com.alibaba.boot : nacos-discovery-spring-boot-starter Optional jar
com.alibaba.nacos : nacos-client jar 0.8.2
org.springframework.boot : spring-boot-starter jar 2.1.2.RELEASE

Project Modules

There are no modules declared in this project.

Build StatusLicense Maven Central

Micro-job is a distributed task scheduling and execution framework, which accesses data internally through the Rest path shared by Jersey of each component.

Detailed development documentation Visit official website

Noun interpretation:

consumer -> Task Consumption Node

schedule -> Task Scheduler

provider -> Task Producer

registry -> Task Registry

Registry

Regisryserves 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.

Create the SpringBoot'project through idea and eclipse tools and add the following dependencies to the pom.xml' file.

<dependency>
    <groupId>com.github.hengboy</groupId>
	<artifactId>spring-boot-starter-registry-memory</artifactId>
	<version>{lastVersion}</version>
</dependency>

Add the application.yml'configuration file to the resources' resource directory as follows:

server:
   port: 9000
hengboy:
  job:
    registry:
      # ask Registry Node Registration
      away: memory

Schedule

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. In production tasks, the scheduler nodes'that perform task scheduling are also filtered according to the load balancing strategy' of the scheduler. Create SpringBoot'project through idea' and eclipse'tools and add the following dependencies to the pom.xml' file.

<dependency>
    <groupId>com.github.hengboy</groupId>
    <artifactId>spring-boot-starter-schedule</artifactId>
    <version>{lastVersion}</version>
</dependency>

Add the application.yml'configuration file to the resources' resource directory as follows:

server:
   port: 8081
hengboy:
  job:
    registry:
      # Maintain consistency with task registry node registration
      away: memory
    schedule:
      # Memory Scheduler handles task queues and storage of task logs
      job-store-type: memory  

Consumer

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'. Create SpringBoot'project through idea' and eclipse'tools and add the following dependencies to the `pom.xml' file.

<dependency>
	<groupId>com.github.hengboy</groupId>
	<artifactId>spring-boot-starter-consumer</artifactId>
	<version>{lastVersion}</version>
</dependency>

Add the application.yml'configuration file to the resources' resource directory as follows:

server:
   port: 8082
hengboy:
  job:
    registry:
      # Maintain consistency with task registry node registration
      away: memory

Example Of JOB Definition

Let's define a simple `Job', as follows:

@Job(jobExecuteAway = JobExecuteAwayEnum.ONCE)
public class TestJob implements MicroJob {
    /**
     * logger instance
     */
    static Logger logger = LoggerFactory.getLogger(TestJob.class);

    @Override
    public JobExecuteResult execute(JobExecuteParam jobExecuteParam) throws JobException {
        logger.info("Key:{},Param:{}", jobExecuteParam.getJobKey(), jobExecuteParam.getJsonParam());
        return JobExecuteResult.JOB_EXECUTE_SUCCESS;
    }
}

The Job', as defined above, corresponds to JobKey', which is `testJob'.

Provider

The business side adds dependencies and performs MicroJobProvider. newXxxJob'call creation tasks, such as Send mail' notification operation after creating an order'. Create SpringBoot'project through idea' and eclipse'tools and add the following dependencies to the pom.xml' file.

<dependency>
	<groupId>com.github.hengboy</groupId>
	<artifactId>spring-boot-starter-provider</artifactId>
	<version>{lastVersion}</version>
</dependency>

Add the application.yml'configuration file to the resources' resource directory as follows:

server:
  port: 8083
hengboy:
  job:
    registry:
      # Maintain consistency with task registry node registration
      away: memory

JOB Execution Example

@RunWith(SpringRunner.class)
@SpringBootTest
public class ProviderTester {
    /**
     * Registered Task Provider
     */
    @Autowired
    private MicroJobProvider microJobProvider;

    @Test
    public void newJob() {
        // Created tasks are executed only once
        microJobProvider.newOnceJob(OnceJobWrapper.Context()
                // JobKey, which corresponds to tasks defined in consumer, defaults to lowercase class names
                .jobKey("testJob")
                // Customized task queue key, can accurately locate tasks and operate pause, delete and other operations
                .jobQueueKey(UUID.randomUUID().toString())
                // Parameters, parameters of any type, when consumer consumes, are converted to JSON strings
                .param(new HashMap() {
                    {
                        put("name", "admin");
                    }
                })
                .wrapper());
    }
}

Test flow

  1. Start Task Registry
  2. Start Task Scheduling Center
  3. Start Task Consumer Node
  4. Execute the Provider Tester # newJob unit test method

Folders

​```
.
├── micro-job-autoconfigure
├── micro-job-dependencies
├── micro-job-samples
│   ├── sample-consumer
│   ├── sample-provider
│   ├── sample-registry-consul
│   ├── sample-registry-memory
│   ├── sample-registry-redis
│   ├── sample-registry-zookeeper
│   ├── sample-schedule
│   ├── pom.xml
│   └── README.md
├── micro-job-starters
│   ├── spring-boot-starter
│   ├── spring-boot-starter-provider
│   ├── spring-boot-starter-registry-consul
│   ├── spring-boot-starter-registry-memory
│   ├── spring-boot-starter-registry-redis
│   ├── spring-boot-starter-registry-zookeeper
│   ├── spring-boot-starter-schedule
│   └── pom.xml
├── .travis.yml
├── LICENSE
├── pom.xml
└── README.md
​```

License

The Apache License

Versions

Version
0.0.3.RELEASE
0.0.2.RELEASE
0.0.1.RELEASE