com.github.hengboy:micro-job-dependencies

spring-boot-micro-job 是一款分布式任务执行框架 核心组件: 1. 调度中心 2. 注册中心 3. 任务生产者 4. 任务消费者

License

License

GroupId

GroupId

com.github.hengboy
ArtifactId

ArtifactId

micro-job-dependencies
Last Version

Last Version

0.0.3.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

spring-boot-micro-job 是一款分布式任务执行框架 核心组件: 1. 调度中心 2. 注册中心 3. 任务生产者 4. 任务消费者
Project URL

Project URL

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

Download micro-job-dependencies

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
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