1. The XXL – the JOB description

XXL-JOB is a lightweight distributed task scheduling framework. It’s core design goal is to develop quickly and learn simple, lightweight, and easy to expand. Now, it’s already open source, and many companies use it in production environments, real “out-of-the-box”.

Xxl-job is a lightweight distributed task scheduling platform, whose core design goal is rapid development, simple learning, lightweight and easy to expand. Now open source and access to many companies online product lines, out of the box.

— GIT project introduction from xxl-job

For details about XXL-job, see the Chinese documentation on the official website. Xxl-job supports distributed and dynamic task addition and permission control.

2. Set up XXL-job project

① Download source code
https://github.com/xuxueli/xxl-job/
Copy the code
(2) execute SQL
xxl-job-2.1.1\xxl-job-2.1.1\doc\db\tables_xxl_job.sql
Copy the code
3 Modifying the Configuration
# # # XXL - job, datasource spring. The datasource. Url = JDBC: mysql: / / 127.0.0.1:3306 / xxl_job? Unicode=true&characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=root_pwd spring.datasource.driver-class-name=com.mysql.jdbc.Driver ### xxl-job, AccessToken = = xxl.job. AccessToken = = xxl.job. AccessToken =Copy the code

Note that the configuration address of the subproject must be the same as the address of the access page of admin:

### xxl-job admin address list, such as "http://address" or "http://address01,http://address02" XXL. Job. Admin. Addresses = http://127.0.0.1:8080/xxl-job-adminCopy the code
④ Start the project

The first thing we want to do is start admin in the project, and then start xxl-job-executor-samples under xxl-job-executor-samples. Here we do it. The easier way to do it here is through the SpringBoot example, which is what the author recommends.

After start-up of access control center address: http://localhost:8080/xxl-job-admin (the actuators will be used to address, as the callback address)

The default login account is admin/123456. The following figure shows the login page

For job configuration, please refer to the Demo example, and then we will add the BEAN mode, named @service name:

/ * * * task Handler example (Bean mode) development steps: * * * 1, inheritance, "IJobHandler" : "com. XXL. Job. Core. Handler. IJobHandler"; * 2, register with Spring container@Component"Annotations, scanned by the Spring container as Bean instances; * 3, register to actuator factory:@JobHandler(value=" custom JobHandler name ") annotation that corresponds to the jobHandler property value of the new task in the dispatch center. * 4. Execute log: use "xxljoblogger. log" to print execute log; * *@author xuxueli 2015-12-19 19:43:36
 */
@JobHandler(value="demoJobHandler")
@Component
public class DemoJobHandler extends IJobHandler {

	@Override
	public ReturnT<String> execute(String param) throws Exception {
		XxlJobLogger.log("XXL-JOB, Hello World.");
		System.out.println("XXL-JOB, Hello World.");
		for (int i = 0; i < 5; i++) {
			XxlJobLogger.log("beat at:" + i);
			TimeUnit.SECONDS.sleep(2);
		}
		returnSUCCESS; }}Copy the code

3. Problem summary

  • Can’t connect to the database? You need to configure the connection related to the Datasource in admin and enter the correct password.
  • The execution log is in progress and the callback failed? The subproject must be configured with the same access address of admin for callback.
  • Can’t find the coding interface? GLUE mode can only be used to write code using the interface and support version rollback if it is selected during addition.
  • Does actuator management not take effect? AppName must be the same as that in the configuration. The IP address to be manually added must be the same as the external netty port number (not the tomcat autumn startup port number). The default value is 9999.