All Products
Search
Document Center

SchedulerX:Connect to SchedulerX over the Internet from an on-premises environment

Last Updated:Nov 20, 2023

If you use SchedulerX in the Internet region, you can connect machines or containers that can access the Internet to SchedulerX. For example, you can connect third-party machines or on-premises development environments that can access the Internet to SchedulerX. This topic describes how to connect to SchedulerX over the Internet from an on-premises environment to perform testing and development.

Prerequisites

  • SchedulerX is activated. For more information, see Activate SchedulerX.

  • Resources are created. For more information, see Create resources.

    Note

    Make sure that you select the Internet region when you create an application.

Procedure

  1. Add the SchedulerxWorker dependency to the pom.xml file of the application. The configurations that are used to initialize SchedulerxWorker vary based on the application type:

    Java or Spring application

    <dependency>
      <groupId>com.aliyun.schedulerx</groupId>
      <artifactId>schedulerx2-worker</artifactId>
      <version>${schedulerx2.version}</version>
      <!--If you use logback, you must exclude log4j and log4j 2. -->
      <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 application

    <dependency>
      <groupId>com.aliyun.schedulerx</groupId>
      <artifactId>schedulerx2-spring-boot-starter</artifactId>
      <version>${schedulerx2.version}</version>
      <!-- If you use Logback, you must exclude Log4j and Log4j 2. -->
      <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>                   
  2. Obtain the access configurations of the application, such as the Internet region and the acm.aliyun.com endpoint.

    1. Log on to the SchedulerX console. In the top navigation bar, select the Internet region from the drop-down list.

    2. In the left-side navigation pane, click Application Management. On the Application Management page, find the application that you want to manage and click Access configuration in the Operation column.

      image.png

      image.png

      From the drop-down list, select an access method to obtain the access configurations. The displayed access configurations vary based on the selected access method. Rectangular Box ① in the preceding figure shows the drop-down list.

  3. Initialize SchedulerxWorker. The configurations that are used to initialize SchedulerxWorker vary based on the application type:

    Java application

    Initialize SchedulerxWorker by using the main function.

    public void initSchedulerxWorker() throws Exception {
        SchedulerxWorker schedulerxWorker = new SchedulerxWorker();
        schedulerxWorker.setEndpoint("xxxx");
        schedulerxWorker.setNamespace("xxxx");
        schedulerxWorker.setGroupId("xxxx");
        //If your agent version is 1.2.1 or later, specify an application key.
        schedulerxWorker.setAppKey("xxxx");
        schedulerxWorker.init();
    }

    In the Access configuration panel, click One click copy to copy the access configurations to the destination configuration file, or replace the values of schedulerxWorker.setEndpoint, schedulerxWorker.setNamespace, schedulerxWorker.setGroupId, and schedulerxWorker.setAppKey with the values obtained in Step 2.

    Note
    • If an application provides multiple services or you want to classify the scheduled jobs of an application, you can create multiple groups. For example, you create a group named animals.dogs and a group named animals.cats for the animals application. In this case, you do not need to separately add instances to the groups. You need to only append the group names to groupId= in the configurations of the application agent. Example: groupId=animals.dogs,animals.cats.

    • When you initialize SchedulerxWorker, you can add more configurations. For more information, see SchedulerxWorker parameters.

    Spring application

    Inject the SchedulerxWorker bean into the XML configuration file of the application.

    <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>
        <!--If your agent version is 1.2.1 or later, you must specify the application key. -->
        <property name="appKey">
          <value>${appKey}</value>
        </property>
      
    </bean>

    In the Access configuration panel, click One click copy to copy the access configurations to the destination configuration file, or replace the values of ${endpoint}, ${namespace}, ${groupId}, and ${appKey} with the values obtained in Step 2.

    Spring Boot application

    Add the following configurations to the application.properties file:

    spring.schedulerx2.endpoint=${endpoint}
    spring.schedulerx2.namespace=${namespace}
    spring.schedulerx2.groupId=${groupId}
    # If your agent version is 1.2.1 or later, specify an application key.
    spring.schedulerx2.appKey=${appKey} 

    In the Access configuration panel, click One click copy to copy the access configurations to the destination configuration file, or replace the values of ${endpoint}, ${namespace}, ${groupId}, and ${appKey} with the values obtained in Step 2.

    Note

    If an application provides multiple services or you want to classify the scheduled jobs of an application, you can create multiple groups. For example, you create a group named animals.dogs and a group named animals.cats for the animals application. In this case, you do not need to separately add instances to the groups. You need to only append the group names to groupId= in the configurations of the application agent. Example: groupId=animals.dogs,animals.cats.

  4. Create the JavaProcessor class in the application to implement job scheduling.

    The following sample code provides an example on how to implement the JavaProcessor class that prints hello schedulerx2.0 on schedule:

    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);
        }
    }          
  5. Run the application in the on-premises environment.

Verify the result

  1. Publish the application to Alibaba Cloud after the application is connected to SchedulerX.

  2. Log on to the SchedulerX console.

  3. In the top navigation bar, select a region.

  4. In the left-side navigation pane, click Application Management.

  5. View Total number of instances on the Application Management page.

    • If the Total number of instances column displays 0, the application is not connected to SchedulerX. Check and modify the on-premises application.

    • If the Total number of instances column does not display 0, your application is connected to SchedulerX. Click View instances in the Operation column to view the instances in the Connect to an instance panel.