SchedulerX V2.0 is compatible with XXL-JOB. SchedulerX V2.0 supports the @XxlJob
and @JobHandler
annotations. You can use SchedulerX V2.0 to schedule XXL-JOB jobs without the need to modify job code.
Background information
XXL-JOB is an out-of-the-box and lightweight distributed job scheduling system. XXL-JOB is designed for fast development, simple learning, and easy expansion. XXL-JOB is a well-known scheduling system in open source communities. Multiple enterprises use XXL-JOB in production environments. Open source XXL-JOB is licensed under General Public License (GPL). Therefore, cloud service providers cannot manage XXL-JOB jobs on their platforms for enterprises and charge service fees. Enterprises must create self-managed jobs. This increases the costs of training, servers, and manpower. SchedulerX V2.0 is a job scheduling platform provided by Alibaba Cloud for commercial use. SchedulerX V2.0 is compatible with XXL-JOB. You can use SchedulerX V2.0 to manage XXL-JOB jobs without the need to modify the code of the jobs.
SchedulerX V2.0 provides the following benefits:
Maintenance-free and cost-effective
To create and run self-managed XXL-JOB jobs, you must prepare at least two servers and one database. If you use SchedulerX V2.0 to manage XXL-JOB jobs, you can reduce the server costs and O&M costs.
High capacity and precise scheduling
Open source XXL-JOB uses database locking to prevent data races. This ensures that only one node runs jobs at a point in time but increases the loads of the database. Statistics indicate that the response latency affects user experience when XXL-JOB processes more than 10,000 jobs at a minute granularity. The response latency is even higher when XXL-JOB processes jobs at a second granularity. SchedulerX V2.0 uses a distributed architecture. SchedulerX V2.0 schedules different jobs to different servers and supports lock-free data races. SchedulerX V2.0 supports horizontal scaling and can schedule millions of jobs. SchedulerX V2.0 uses a dedicated architecture to ensure low latency for jobs that must be triggered at a second granularity. SchedulerX V2.0 is suitable for real-time workloads that need to run jobs at a second granularity. SchedulerX V2.0 also supports one-time jobs. You can use SchedulerX V2.0 to run a one-time job at a specific point in time. After SchedulerX V2.0 completes the job, it automatically deletes the job. You can use one-time jobs to send notifications or close orders at a scheduled point in time.
Advanced features
Workflows: SchedulerX V2.0 allows you to use workflows to orchestrate jobs in a visualized manner.
Throttling: SchedulerX V2.0 allows you to use preemptible queues to schedule jobs based on priorities.
Resource isolation: SchedulerX V2.0 supports namespace-level and application-level resource isolation and multi-tenant permission management.
High availability
SchedulerX V2.0 uses a high-availability architecture and creates multiple replicas for each job. The high availability of SchedulerX V2.0 is tested by the internal business of Alibaba Group, such as Double 11 events and disaster recovery drills. SchedulerX V2.0 can schedule jobs as expected even if two cluster nodes fail or when a power outage occurs in a data center.
Alerting and O&M for commercial use
SchedulerX V2.0 is compatible with email alerts and basic O&M features that are provided by XXL-JOB. SchedulerX V2.0 also provides alerting and O&M features for commercial use.
Alerting: SchedulerX V2.0 can send alert notifications by using DingTalk messages, text messages, or phone calls.
O&M: SchedulerX 2.0 allows you to rerun failed jobs, update job outputs, mark jobs as completed, view stacks, and terminate jobs.
Differences between XXL-JOB based on SchedulerX V2.0 and open source XXL-JOB
The following table describes the differences between XXL-JOB based on SchedulerX V2.0 and open source XXL-JOB.
Feature | Open source XXL-JOB | SchedulerX V2.0-based XXL-JOB |
Java jobs | ||
Go jobs | ||
Script jobs | ||
HTTP jobs | ||
Standalone | ||
Sharding broadcast | ||
MapReduce | ||
Routing policies | First, last, round-robin, and random | Round-robin |
Time-based scheduling | cron | cron, fixed_rate, fixed_delay, and one_time |
Workflows | ||
O&M operations | Run one-time jobs and terminate jobs | Run one-time jobs, terminate jobs, rerun jobs, refresh historical data, and mark jobs as completed |
Log query | Logs are stored on on-premises executors. If executors crash down, logs are lost. | Logs of the last two weeks are stored in Logstores of Simple Log Service provided by Alibaba Cloud and support for query. |
Observability | Historical records and dashboard | Historical records, dashboard, operational records, stack view, and tracing analysis |
Monitoring and alerting | Email, DingTalk, Lark, WeCom, custom webhook, text message, and phone call | |
High availability and disaster recovery | Self-responsible for disaster recovery of databases and servers | Support for multi-data center disaster recovery in the same region |
User permissions | User isolation and password-based logon | Support for single sign-on (SSO) and fine-grained permission management of main accounts, Resource Access Management (RAM) users, and RAM roles |
Graceful shutdown | ||
End-to-end canary release | ||
Throttling |
Connect XXL-JOB to SchedulerX V2.0
To use SchedulerX V2.0 to manage XXL-JOB jobs, modify the pom.xml file of your application. Remove the dependencies of
com.xuxueli:XXL-JOB-core
, add the dependencies of the SchedulerX agent, and then add thecom.aliyun:schedulerx2-plugin-xxljob
plug-in.The XXL-JOB interface is reconstructed in V2.3.x. Therefore, you must select a connection method based on the version of open source XXL-JOB that you use. The following examples show the configurations of a sample application named
schedulerx2-spring-boot-starter
:For more information about how to use SchedulerX V2.0 to manage jobs in open source XXL-JOB V2.3.x, see Demo.
schedulerx2.version
specifies the latest version of the client, such as<version>1.11.5</version>
. For more information, see Release notes for SchedulerX SDK for Java.<!-- Annotation xxl-job-core --> <!-- <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> <version>${project.parent.version}</version> </dependency> --> <! -- Add the schedulerx dependency --> <dependency> <groupId>com.aliyun.schedulerx</groupId> <artifactId>schedulerx2-spring-boot-starter</artifactId> <version>${schedulerx2.version}</version> </dependency> <! -- Add schedulerx2-plugin-xxljob --> <dependency> <groupId>com.aliyun.schedulerx</groupId> <artifactId>schedulerx2-plugin-xxljob</artifactId> <version>2.3.5</version> </dependency>
For information about how to use SchedulerX V2.0 to manage jobs in open source XXL-JOB of a version that is earlier than V2.2.x, see Demo.
schedulerx2.version
specifies the latest version of the client, such as<version>1.11.5</version>
. For more information, see Release notes for SchedulerX SDK for Java.<!-- Annotation xxl-job-core --> <!-- <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> <version>${project.parent.version}</version> </dependency> --> <! -- Add the schedulerx dependency --> <dependency> <groupId>com.aliyun.schedulerx</groupId> <artifactId>schedulerx2-spring-boot-starter</artifactId> <version>${schedulerx2.version}</version> </dependency> <! -- Add schedulerx2-plugin-xxljob --> <dependency> <groupId>com.aliyun.schedulerx</groupId> <artifactId>schedulerx2-plugin-xxljob</artifactId> <version>2.2.4</version> </dependency>
Add the following configurations to the agent.properties file. For more information, see Use the SchedulerX agent to connect an application to SchedulerX (script or HTTP jobs).
spring.schedulerx2.endpoint=192.xx.xx.xx spring.schedulerx2.namespace=20e90ffc**** spring.schedulerx2.groupId=679xxx spring.schedulerx2.appKey=71BCC0Exxx
Use the @XxlJob annotation to create a job
Refer to the open source XXL-JOB-executor-sample-springboot
project and create a job based on the following sample code:
/**
* Example of simple jobs in Bean mode
*/
@XxlJob("demoJobHandler")
public ReturnT<String> demoJobHandler(String param) throws Exception {
System.out.println("XXL-JOB, " + param);
return ReturnT.SUCCESS;
}
Log on to the SchedulerX console.
In the left-side navigation pane, click Task Management.
In the top navigation bar of the Task Management page, select a region. Then, select a namespace from the drop-down list to the right of Task Management and click Create task. For more information about the parameters, see Create a job.
On the Task Management page, find the job that you created and click Run once in the Operation column.
On the Task Management page, find the job that you want to manage and choose more > Historical records in the Operation column to view Task instance records.
Use the @JobHandler annotation to create a job
The following code block shows an example:
@JobHandler(value="HelloJobHandler")
@Componentpublic class HelloJobHandler extends IJobHandler {
@Override
public ReturnT<String> execute(String param) throws Exception {
System.out.println("HelloJobHandler: " + param);
return SUCCESS;
}
}
Log on to the SchedulerX console.
In the left-side navigation pane, click Task Management.
In the top navigation bar of the Task Management page, select a region. Then, select a namespace from the drop-down list to the right of Task Management and click Create task. For more information about the parameters, see Create a job.
On the Task Management page, find the job that you created and click Run once in the Operation column.
On the Task Management page, find the job that you want to manage and choose more > Historical records in the Operation column to view Task instance records.
Use sharding broadcast to create a job
In the following sample code, the @XxlJob annotation is used:
/**
* Sharding broadcast job
*/
@XxlJob("shardingJobHandler")
public ReturnT<String> shardingJobHandler(String param) throws Exception {
// Sharding parameters
int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();
XxlJobLogger.log("Sharding parameters: Current shard index = {}, Total number of shards = {}", shardIndex, shardTotal);
System.out.println("Sharding parameters: Current shard index ="+ shardIndex + ", Total number of shards = " + shardTotal);
// Business logic
for (int i = 0; i < shardTotal; i++) {
if (i == shardIndex) {
System.out.println("Shard " + i + ", Process the matching shards.");
XxlJobLogger.log("Shard {}, Process the matching shard", i);
} else {
XxlJobLogger.log("Shard {}, Ignore", i);
}
}
return ReturnT.SUCCESS;
}
Log on to the SchedulerX console.
In the left-side navigation pane, click Task Management.
In the top navigation bar of the Task Management page, select a region. Then, select a namespace from the drop-down list to the right of Task Management and click Create task. For more information about the parameters, see Create a job.
On the Task Management page, find the job that you created and click Run once in the Operation column.
On the Task Management page, find the job that you want to manage and choose more > Historical records in the Operation column to view Task instance records.