When deployed in a public region, SchedulerX accepts connections from any machine or container with public network access, including non-Alibaba Cloud machines and local development environments. This topic describes how to connect to SchedulerX from a local environment for testing and development.
Prerequisites
-
Note
When creating the application, select the Internet region.
Procedure
-
Add the SchedulerxWorker dependency to your application's pom.xml file. The initialization of SchedulerxWorker varies for different applications:
Standard Java or Spring
<dependency> <groupId>com.aliyun.schedulerx</groupId> <artifactId>schedulerx2-worker</artifactId> <version>${schedulerx2.version}</version> <!--If you use logback, exclude log4j and log4j2. --> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </exclusion> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency>Spring Boot
<dependency> <groupId>com.aliyun.schedulerx</groupId> <artifactId>schedulerx2-spring-boot-starter</artifactId> <version>${schedulerx2.version}</version> <!-- If you use logback, exclude log4j and log4j2 --> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> </exclusion> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> -
Obtain the access configuration for your application: the Internet and its endpoint (acm.aliyun.com).
-
Log on to the MSE SchedulerX console. In the top navigation bar, switch the region to Internet.
-
In the left-side navigation pane, click Application Management. On the Application Management page, find your application and click Access Configuration in the Actions column to get the configuration for the corresponding access method.
In the Access Configuration dialog box, the Access Method drop-down list on the left contains options for Spring Boot, Java, Spring, Agent, k8s, and Helm. After selecting Spring Boot, the right pane displays the configuration parameters:
schedulerx2.endpoint=acm.aliyun.com,schedulerx2.namespace,schedulerx2.groupId, andschedulerx2.appKey(required for version 1.2.1 and later).Select an access method to view its configuration.
-
-
Initialize SchedulerxWorker. The initialization process differs for different applications:
Standard Java
Initialize SchedulerxWorker in the main function.
public void initSchedulerxWorker() throws Exception { SchedulerxWorker schedulerxWorker = new SchedulerxWorker(); schedulerxWorker.setEndpoint("xxxx"); schedulerxWorker.setNamespace("xxxx"); schedulerxWorker.setGroupId("xxxx"); // Set the appKey for versions 1.2.1 and later. schedulerxWorker.setAppKey("xxxx"); schedulerxWorker.init(); }In the Access Configuration panel, click Copy to copy the configuration to the corresponding configuration file. Alternatively, set
schedulerxWorker.setEndpoint,schedulerxWorker.setNamespace,schedulerxWorker.setGroupId, andschedulerxWorker.setAppKeyto the values that you obtained in Step 2.Note-
If an application contains multiple services or you need to categorize scheduled tasks, you can create multiple groups. For example, for the application
animals, you can create two new groups:animals.dogsandanimals.cats. You do not need to provision separate instances to connect to these two groups. You only need to list both groups aftergroupId=in your application client, such asgroupId=animals.dogs,animals.cats. -
For more configuration options when initializing the SchedulerxWorker client, see SchedulerxWorker configuration parameters.
Spring
Inject the SchedulerxWorker bean in the XML configuration file.
<bean id="schedulerxWorker" class="com.alibaba.schedulerx.worker.SchedulerxWorker"> <property name="endpoint"> <value>${endpoint}</value> </property> <property name="namespace"> <value>${namespace}</value> </property> <property name="groupId"> <value>${groupId}</value> </property> <!-- Set the appKey parameter for versions 1.2.1 and later. --> <property name="appKey"> <value>${appKey}</value> </property> </bean>In the Access Configuration panel, click Copy to copy the configuration to the corresponding configuration file. Alternatively, replace
${endpoint},${namespace},${groupId}, and${appKey}with the values that you obtained in Step 2.Spring Boot
In the application.properties file, add the following configuration:
spring.schedulerx2.endpoint=${endpoint} spring.schedulerx2.namespace=${namespace} spring.schedulerx2.groupId=${groupId} # Set the appKey for versions 1.2.1 and later. spring.schedulerx2.appKey=${appKey}In the Access Configuration panel, click Copy to copy the configuration to the corresponding configuration file. Alternatively, replace
${endpoint},${namespace},${groupId}, and${appKey}with the values that you obtained in Step 2.NoteIf an application involves multiple business services or you need to categorize scheduled tasks, you can create multiple groups. For example, for an application named animals, you can create two groups: animals.dogs and animals.cats. You do not need to run separate instances for each group. Instead, configure the groups in your client by listing them in the groupId parameter, for example,
groupId=animals.dogs,animals.cats. -
-
Create a
JavaProcessorclass in your application to implement a scheduled task.The following sample code shows how to implement a simple
JavaProcessorclass that periodically printshello schedulerx2.0.package com.aliyun.schedulerx.test.job; import com.alibaba.schedulerx.worker.domain.JobContext; import com.alibaba.schedulerx.worker.processor.JavaProcessor; import com.alibaba.schedulerx.worker.processor.ProcessResult; @Component public class MyHelloJob extends JavaProcessor { @Override public ProcessResult process(JobContext context) throws Exception { System.out.println("hello schedulerx2.0"); return new ProcessResult(true); } } -
Run the local application.
Verify the result
Log on to the MSE SchedulerX console. In the left navigation bar, click Application Management and view the Total Instances of the target application.

If Total Instances is 0, the application failed to connect. Check and modify the local application.
If Total Instances is not 0 and shows the number of connected instances, the application is successfully connected.