How to Periodically Execute Integration Processes¶ What you'll build¶ The sections below demonstrate an example of a scheduled trigger (task) that injects an XML message and prints it in the server logs. Concepts and artifacts used¶ Sequence Log Mediator Drop Mediator Scheduled trigger Let's get started!¶ Step 1: Set up the workspace¶ You need Visual Studio Code (VS Code) with the WSO2 Integrator: MI for VS Code extension installed. Info See the Install WSO2 Integrator: MI for VS Code documentation to learn how to install WSO2 Integrator: MI for VS Code. Step 2: Develop the integration artifacts¶ Follow the instructions given in this section to create and configure the required artifacts. Create an Integration Project¶ The Integration project will contain all the required artifacts for the integration solution. Launch VS Code with the WSO2 Integrator: MI extension installed. Click on the WSO2 Integrator: MI icon on the Activity Bar of the VS Code editor. Click Create New Project on Design View. Next, the Project Creation Form will be opened. In the Project Creation Form, enter ScheduleTaskTutorial as the Project Name. Provide a location under Select Project Directory. Click Create. Now let's start designing the integration by adding the necessary artifacts. Create a Scheduled trigger (task)¶ In the Add Artifact interface, under Create an Integration, click on Automation. This opens the Automation Form. Note WSO2 Integrator: MI supports automation flows that can be triggered either on a schedule or at server startup. It provides two types of automations: Scheduled Triggers (Task) – Executes a task repeatedly based on a defined interval or cron expression. (You will explore this in this tutorial.) Startup Triggers – Executes a task once when the WSO2 Integrator: MI starts, runs the integration, and then shuts down. To learn more, refer to Running the WSO2 Integrator: MI in Automation Mode. Enter the details given below to create a new REST API. Property Value Description Automation Type Scheduled Trigger Specifies the type of automation to be created. Task Name InjectXMLTask The name assigned to the scheduled trigger (task). Trigger Mode Fixed Interval Defines how often the task executes. Fixed Interval triggers the task repeatedly after a set time, or you can choose Cron to configure a cron expression. Interval 5 The execution interval in seconds. Since Trigger Indefinitely is enabled, the task will continue running indefinitely at the given interval. Message <request xmlns=""><location><city>London</city><country>UK</country></location></request> The XML payload that will be injected when the task is triggered. Click Create. This will open the integration flow (sequence) that will be executed by the configured Scheduled Trigger. Update the mediation flow¶ You can now start designing the integration logic. We will add a Log Mediator to log the message when the Scheduled Trigger executes the flow. Click on the + icon on the canvas to open the Mediator Palette. Under Mediators, select the Log mediator. Provide City = ${xpath("//city")} as the Message, and click Add to insert the Log mediator into the integration flow. Click on the + icon after the Log mediator to open the Mediator Palette. We will add a Drop Mediator to stop processing the current message after it is logged. Under Mediators, select the Drop mediator, and click Add to insert it into the integration flow. You have successfully completed the integration flow with the scheduled trigger and logged the message. For reference, you can review the configured scheduled trigger (task) and the sequence. InjectXMLTask Info You can view the source view by clicking on the Show Source (</>) icon located in the top right corner of the VS Code. Design ViewSource View <?xml version="1.0" encoding="UTF-8"?> <task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="InjectXMLTask" xmlns="http://ws.apache.org/ns/synapse"> <trigger interval="5"/> <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message"><request xmlns=""><location><city>London</city><country>UK</country></location></request></property> <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="injectTo" value="sequence"/> <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="sequenceName" value="InjectXMLTaskSequence"/> </task> InjectXMLTaskSequence Info You can view the source view by clicking on the Show Source (</>) icon located in the top right corner of the VS Code. Design ViewSource View <?xml version="1.0" encoding="UTF-8"?> <sequence name="InjectXMLTaskSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse"> <log category="INFO" logMessageID="false" logFullPayload="false"> <message>City = ${xpath("//city")}</message> </log> <drop/> </sequence> Step 3: Build and run the artifacts¶ Now that you have developed an integration using the WSO2 Integrator: MI for the Visual Studio Code plugin, it's time to deploy the integration to the WSO2 Integrator: MI server runtime. Click the Build and Run icon located in the top right corner of VS Code. Step 4: Test the use case¶ When you run the integration artifact as described in Step 3, you will see the injected XML message being printed in the WSO2 Integrator: MI logs every 5 seconds, in the Output tab of VS Code.