xxl-job (v2.1.0 Release) Executor Registration Principle

Posted by mattclements on Wed, 14 Aug 2019 15:02:26 +0200

Preface

Quatz dependency has been removed in v2.1.0 Release version, which reduces dependency and improves controllability and stability of the system.
The communication scheme used in this version is "NETTY_HTTP" scheme. The actuator is embedded with netty-http-server to provide services, and the dispatching center reuses container ports to provide services.

Actuator registration process
1. Open Executor Management, we add an Executor



AppName: AppName is the only symbol of each cluster of executors, which periodically automatically registers AppName as an object. This configuration can automatically discover registered Executors for use in task scheduling; (AppName configures xxl. job. executor. appName = xxxl-job-executor-sample in the executor's properties file)
Name: The name of the executor, because AppName restricts the composition of letters and numbers, and so on, the readability of the name is not strong, in order to improve the readability of the executor;
Sort: The sort of the executor, where the executor is needed in the system, if the task is added, the list of available executors will be read according to the sort.
Registration method: the way the dispatching center obtains the address of the executor;
Automatic registration: Actuator registers automatically, dispatching center can dynamically find the machine address of the actuator through the underlying registry;
Manual input: Manually input the address information of the actuator, separated by multi-address commas, for use by the dispatching center;
Machine Address: Registration method is valid when "manual input", supporting manual maintenance of the address information of the actuator;

2. Registration process

1) First look at XxlJobConfig in the executor

2) Create the XxlJobSpringExecutor object and initialize the start method

@Configuration
public class XxlJobConfig {
  
   ..............................................
   //Create the XxlJobSpringExecutor object and initialize the start method to execute XxlJobSpringExecutor
    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobSpringExecutor xxlJobExecutor() {
        logger.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppName(appName);
        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobSpringExecutor;
    }

3) Execute the start() method of XxlJobSpringExecutor

public class XxlJobSpringExecutor extends XxlJobExecutor implements ApplicationContextAware {
    @Override
    public void start() throws Exception {
        //Initialize JobHandler Warehouse Registration JobHandler 
        // init JobHandler Repository
        initJobHandlerRepository(applicationContext);
        // refresh GlueFactory
        GlueFactory.refreshInstance(1);
        //Then execute the start() method of XxlJobExecutor
        // super start
        super.start();
    }
    }

Then execute the start() method of XxlJobExecutor

public class XxlJobExecutor  {
//Execute the start() method
 public void start() throws Exception {

        //Initialize admin scheduling center proxy class
        //Polling dispatch center addresses, multiple addresses separated by commas, whenever an address is encountered, the proxy class AdminBiz is generated.
        initAdminBizList(adminAddresses, accessToken);
        
        //admin's service startup: enables the executor to invoke the interface of the dispatch center
        initRpcProvider(ip, port, appName, accessToken);
    }

}

Execute getObject()

getObject() completes the service registration operation by sending a request to the dispatching center
The agent of xxl-rpc is acquired by reflection, and then registered with the dispatching center by the address of the dispatching center.

Topics: Netty