-
Notifications
You must be signed in to change notification settings - Fork 8.3k
SchedulerX en
SchedulerX(Distributed job scheduling) is a component of EDAS, an Alibaba Cloud product. Spring Cloud Alibaba Cloud SchedulerX provides distributed job scheduling in conformity with the Spring Cloud specifications. SchedulerX provides timed job scheduling service with high accuracy with seconds, high stability and high availabiliy, and supports multiple job types, such as simple single-server jobs, simple multi-host jobs, script jobs, and grid jobs.
If you want to use SchedulerX in your project, please use the starter with the group ID as com.alibaba.cloud
and the artifact ID as spring-cloud-starter-alicloud-schedulerX
.
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alicloud-schedulerX</artifactId>
</dependency>
After Spring Cloud Alibaba Cloud SchedulerX Starter is introduced into the client, you only need to complete a few simple configurations and you will be able to initialize the SchedulerX service automatically.
The following is a simple example.
@SpringBootApplication
public class ScxApplication {
public static void main(String[] args) {
SpringApplication.run(ScxApplication.class, args);
}
}
Add the following configurations in the application.properties file.
server.port=18033
# cn-test is the test region of SchedulerX
spring.cloud.alicloud.scx.group-id=***
spring.cloud.alicloud.edas.namespace=cn-test
Before getting the group-id, please Register an Alibaba Cloud account, and then Sign up for EDAS and Sign up for SchedulerX as well.
To get the group-id, refer to the SchedulerX Documentation.
Note
|
When you create a group, please select the “test” region. |
Simple job is the most commonly used job type. You only need to implement the ScxSimpleJobProcessor interface.
The following is a sample of a simple single-server job.
public class SimpleTask implements ScxSimpleJobProcessor {
@Override
public ProcessResult process(ScxSimpleJobContext context) {
System.out.println("-----------Hello world---------------");
ProcessResult processResult = new ProcessResult(true);
return processResult;
}
}
Go to the SchedulerX Jobs page, select the “Test” region, and click “Create Job” on the upper-right corner to create a job, as shown below.
Job Group: Test——***-*-*-****
Job process interface:SimpleTask
Type: Simple Single-Server Job
Quartz Cron Expression: Default Option——0 * * * * ?
Job Description: Empty
Custom Parameters: Empty
The job above is a “Simple Single-Server Job”, and speficied a Cron expression of "0 * * * * ?" . This means that the job will be executed once and once only in every minute.
For more job types, refer to SchedulerX Documentation.
The previous examples shows how to use SchedulerX in the “Test” region, which is mainly used for local testing.
At the production level, you need to complete some other configurations in addition to the group-id and namespace as mentioned above. See examples below:
server.port=18033
# cn-test is the test region of SchedulerX
spring.cloud.alicloud.scx.group-id=***
spring.cloud.alicloud.edas.namespace=***
# If your application runs on EDAS, you do not need to configure the following.
spring.cloud.alicloud.access-key=***
spring.cloud.alicloud.secret-key=***
# The following configurations are not mandatory. You can refer to the SchedulerX documentation for details.
spring.cloud.alicloud.scx.domain-name=***
The way to get the group-id is the same as described in the previous examples, and you can get the namespace by clicking “Namespaces” in the left-side navigation pane of the EDAS console.
Note
|
Group-id must be created within a namespace. |
Access-key and secret-key are the AK/SK of your Alibaba Cloud account. If you deploy you applications on EDAS, then you do not need to fill in this information. Otherwise please go to Security Information to get your AccessKeys.
Domain-name is not mandatory. You can refer to SchedulerX Documentation for details.
- 文档
- Documents
- Open Source components
- Commercial components
- Example
- awesome spring cloud alibaba