All Products
Document Center

Scheduled Task Based on Message

Last Updated: Aug 21, 2020

This topic describes how to use Scheduler, including configuring Scheduler and SOFAMQ. The content described in this topic includes:

  1. Coding: Integrate Scheduler. To download the sample code, see Download code.
  2. Operations on the console: After completing local coding, you must submit related configurations on the console of the server, including the configurations of the scheduled task, message type, and subscription relationship.
  3. Verification based on logs: After deploying a sample app on the SOFAStack platform, you need to view logs to check whether the app starts running properly.

Preceding courses

The sample code in this course is developed based on SOFABoot. Before starting this course, ensure that you are familiar with SOFABoot and the relationship between Scheduler and SOFAMQ.


Download code

Click here to download the sample project.

Run code

The scheduled tasks are managed and controlled on the cloud. Therefore, you must deploy the app on the cloud.

Adjust the configuration

The file of SOFABoot contains three parameters related to the workspace. Before deploying the app on the cloud, determine the target workspace, check the workspace parameters, and modify them as needed. For more information, see SOFARPC > Service publication and reference > Reference the SOFARPC service. Related parameters include:

  • com.antcloud.antvip.endpoint

Application Deployment

The sample app is a common SOFABoot Core project. Pack it and deploy it on the cloud by referring to SOFABoot > Compilation and Deployment > Cloud Deployment.

Operations on the console

Configure a scheduled task

Configure a scheduled task by referring to Add and manage message-based scheduled tasks. Ensure that the task name is the same as that specified with eventCode in the code. For more information, see schedulertutorial/schedulertutorial-service/src/main/resources/META-INF/schedulertutorial/schedulertutorial-service.xml.

Configure the message type and subscription relationship

Add the message topic, consumption group, and subscription relationship in the SOFAMQ console. For more information, see topics related to the message type and subscription relationship in SOFAMQ.


  • Ensure that the message topic, event code, and subscription group are the same as those in the code. For more information, see schedulertutorial/schedulertutorial-service/src/main/resources/META-INF/schedulertutorial/schedulertutorial-service.xml.
  • After configuring the message topic and subscription relationship, validate them.

Verification based on logs

Log on to the schedulertutorial ECS on the SOFAStack platform over SSH on the website and view logs in /home/admin/logs/tracelog/msg-sub-digest.log. The log file is sent from SOFAMQ and records logs in the following format. Check the logs to determine whether the sample app starts running properly.

  1. 2017-07-04 22:06:13.334,schedulertutorial,0ba5c708149917717403218544734,0.1.50bafee1,48502cafabf3ae16cbc29896f5cb4752,a1446577617326be85d2853a95c9b098,^8LFHHIA4ZPEX$TP_F_SC,EC_TASK_SCHEDULERTUTORIAL_DEMO,^000001$P-scheduler-prod,00,656B,37ms,dms-server-shared-1-1,0,msgWorkTP-1954168392-1-thread-1,,