Locally debug cloud XXL-JOB jobs

Updated at:
Copy as MD

You can use the on-premises and cloud interconnection feature of Alibaba Cloud Toolkit in IntelliJ IDEA to connect your local applications with cloud-based XXL-JOB applications and improve your development efficiency.

Prerequisites

Before you use Alibaba Cloud Toolkit to enable on-premises and cloud interconnection, complete the following prerequisites:

  • You have created an MSE XXL-JOB instance.

  • IntelliJ IDEA 2018.3 or a later version is installed.

  • You must prepare an ECS instance that you can log on to by using SSH to establish an on-premises and cloud interconnection channel. For more information, see Purchase and use a custom ECS instance.

    Important
    • The ECS instance and the target application must be in the same VPC.

    • The ECS instance must have a public IP address.

    • Key pair authentication is not supported. The SSH connection requires password authentication.

Step 1: Install Alibaba Cloud Toolkit

Note

You can install the plug-in in one of the following two ways:

This section describes how to install the Alibaba Cloud Toolkit plug-in from the IntelliJ IDEA Marketplace.

  1. Start IntelliJ IDEA.

  2. Install the plug-in in IntelliJ IDEA.

    • On macOS: In the top menu bar, choose . In the left-side navigation pane of the Preference page, click Plugins. Search for Alibaba Cloud Toolkit and click Install.

    • On Windows: In the top menu bar, choose . In the left-side navigation pane of the Settings page, click Plugins. Search for Alibaba Cloud Toolkit and click Install.

  3. After installing the plug-in, restart IntelliJ IDEA. The Alibaba Cloud Toolkit icon (Alibaba Cloud Toolkit图标) appears in the toolbar.

Step 2: Configure account and proxy

Configure an Alibaba Cloud account

After installing Alibaba Cloud Toolkit, you must configure an Alibaba Cloud account using an AccessKey ID and AccessKey Secret.

  1. Start IntelliJ IDEA.

  2. In the top menu bar, choose .

  3. In the Settings dialog box, choose .

  4. In the Accounts dialog box, set AccessKey ID and AccessKey Secret, and then click OK.

    If you use the AccessKey ID and AccessKey Secret of a RAM user, ensure the RAM user has at least the permissions to deploy applications. For more information, see Manage RAM user permissions.

    Obtain your credentials as follows:

    • If you already have an Alibaba Cloud account, click Get existing AK/SK in the Accounts dialog box. This redirects you to the Alibaba Cloud logon page. After logging on, you are redirected to the Security Management page to obtain your AccessKey ID and AccessKey Secret.

    • If you do not have an Alibaba Cloud account, click Sign up in the Accounts dialog box to go to the Alibaba Cloud account registration page. After registering, obtain your AccessKey ID and AccessKey Secret as described previously.

Configure a proxy

  1. In the Settings dialog box, choose .

  2. In the Proxy dialog box, click AddProfile and set Profile Name.

  3. Click Add on the right. For Proxy type, select SSH. For Proxy IP and port, use the public IP address of your ECS instance and port 22. For Account, select root. For Login method, select Password and enter the logon password for your ECS instance. Then, click OK.

Step 3: Configure on-premises and cloud interconnection

  1. Start IntelliJ IDEA.

  2. In the top menu bar, choose .

  3. In the Settings dialog box, choose .

  4. In the Microservice dialog box, configure the parameters for on-premises and cloud interconnection.

    Parameter

    Description

    Configuration granularity

    The scope of the on-premises and cloud interconnection feature for your local project. Valid values are Project and Module.

    • (Recommended) Project: A single interconnection configuration is used for the entire project. This is suitable for single-module projects or multi-module projects where modules share the same configuration.

    • Module: For projects with multiple modules where only a specific module needs interconnection, or where modules require different configurations. You must configure each required module individually.

    On-premises and cloud interconnection

    Select on-premises and cloud interconnection to enable the feature.

    When enabled, your local application automatically registers with and subscribes to services in the cloud service registry, allowing mutual calls between local and cloud services.

    If you only need to call cloud services and do not want cloud services to call your local services, select Only subscribe to cloud services, do not register on-premises services.

    Product

    Select Microservices Engine (MSE).

    Region

    Select the region where the MSE instance is located.

    Instance

    Select the MSE instance.

    Local SpringCloud service port

    Enter the service port of your Spring Cloud application in the Local SpringCloud Service Port text box. This field is not required for other application types.

    Proxy

    Select a proxy server.

    Initialize proxy...

    Configure SSH rules to enable on-premises and cloud interconnection.

    Note

    If the last-level SSH proxy in the proxy list is not a root account, you are prompted to provide root permissions for the configuration. After the configuration is complete, you can use the feature. Alternatively, you can configure the proxy manually.

    Advanced configuration

    Select Automatically disable startup prompt to set the display duration of the application startup prompt in milliseconds.

    One-click diagnostics

    If you encounter issues during interconnection, click One-click Diagnostics to troubleshoot problems such as etrans channel startup exceptions and service connection failures.

  5. Click Apply, and then click OK.

Step 4: Run and debug the application

  1. Download the alibabacloud-edas-demo project.

  2. Create an XXL-JOB application.

    1. Log on to the MSE XXL-JOB console and select a region in the top menu bar.

    2. Go to the target XXL-JOB instance. In the left-side navigation pane, choose Application Management and click Create Application.

    3. After creating the application, click Access Configuration in the Actions column. In Access Method 1, click One-click Copy to copy the configuration parameters to the application.properties file of your project. Alternatively, you can use Access Method 2: Restart the Application By Using the -D Parameter (No Modifications of Code and Configuration Files).

      The configuration parameters include xxl.job.admin.addresses, xxl.job.executor.appname, and xxl.job.accessToken.

      Important
      • Ensure the application parameters in the console match the parameters in your project's application.properties file.

      • When using a new version of Alibaba Cloud Toolkit to configure on-premises and cloud interconnection, an instance is already specified. You do not need to configure the xxl.job.admin.addresses parameter.

      • When using an earlier version of Alibaba Cloud Toolkit to configure on-premises and cloud interconnection, an instance is not specified. You must set the xxl.job.admin.addresses parameter to the server address.

    4. After starting the project, check the created application and confirm that the Number of Executors is 1.

      Verify that the executor status is Online.

  3. Create a job.

    Create a JobHandler job, and then click Run Once in the Actions column for that job.

  4. In the left-side navigation pane, click Execution List and verify that the status of the job is Success.

FAQ

  • How do I enable on-premises and cloud interconnection in IntelliJ IDEA using an earlier version of Alibaba Cloud Toolkit?

    When you configure on-premises and cloud interconnection, select Serverless App Engine (SAE) for the Product parameter. Then, click Advanced Configuration in the upper-right corner and select Enable xxl-job interconnection.

References