Skip to content

How to Periodically Execute Integration Processes

What you'll build

The sections below demonstrate an example of scheduling a task (using the default implementation) to inject an XML message and print it in the server logs.

Concepts and artifacts used

Let's get started!

Step 1: Set up the workspace

The following software and configurations are required to proceed with this tutorial:

  • Visual Studio Code (VS Code): with the Micro Integrator extension installed.
  • Java Development Kit (JDK): Ensure the JDK is properly configured in your system's PATH environment variable.
  • Apache Maven: Ensure Apache Maven is installed and its path is correctly set within the system's PATH environment variable.

Info

Follow the Install Micro Integrator for VS Code documentation for a complete installation guide.

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.

  1. Launch VS Code with the Micro Integrator extension installed.

  2. Click on the Micro Integrator icon on the Activity Bar of the VS Code editor.

    MI VS Code Extension

  3. Click Create New Project on Design View.

    Design View Pane Create New Project

    Next, the Project Creation Form will be opened.

  4. In the Project Creation Form, enter ScheduleTaskTutorial as the Project Name.

  5. Provide a location under Select Project Directory.

    create new project

  6. Click Create.

Now let's start designing the integration by adding the necessary artifacts.

Create the Sequence

  1. Navigate to the MI Project Explorer > Sequences.

    create sequence

  2. Hover over Sequences and click the + icon that appears.

    add sequence

  3. In the Sequence Form that appears, provide InjectXMLSequence as the Name.

    Create new sequence

  4. Click Create. Then you will be directed to the MI Overview page.

  5. Click on InjectXMLSequence under Sequences that you have just created to open its diagram view.

  6. Next, add a Log mediator to the sequence. Click the + icon and select Log mediator from the Palette under Mediators > Generic.

    Add log mediator

  7. Enter the following details in the Log details pane.

    • Log Category: INFO
    • Log Level: CUSTOM
  8. Under Properties, click Add Parameter to add a new property with the following details:

    Property Description
    Property Name City
    Property Value //city

  9. Click on EX to set the value to the expression type.

    Log details

  10. Click Save to save the properties.

  11. Click Submit to save the Log details.

  12. Next, add the Drop mediator. Click on the + icon and select Drop mediator from Mediators > Generic.

    Add drop mediator

  13. Click Submit.

Below is the complete source configuration of the Sequence (i.e., the InjectXMLSequence.xml file).

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="InjectXMLSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <log category="INFO" level="custom">
        <property name="City" expression="//city"/>
    </log>
    <drop/>
</sequence>

Create the Scheduled Task

  1. Navigate to the MI Project Explorer > Tasks.

    create sequence

  2. Hover over Tasks and click the + icon that appears.

    add sequence

  3. In the Task Form that appears, enter the following details:

    • Task Name: InjectXMLTask
    • Count: -1
    • Interval (in seconds): 5
    • Message inject destination: sequence
    • Sequence name: InjectXMLSequence
    • Message : Check message format is XML and enter the following as the message:

      <request xmlns="">   <location>   <city>London</city>    <country>UK</country>   </location>    </request>
      
  4. Click Create.

Below is the complete source configuration of the scheduled task.

<?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 count="-1" 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="InjectXMLSequence"/>
</task>

Step 3: Build and run the artifacts

Prerequisites

Before you begin, install Micro Integrator on your machine:

  1. Go to the WSO2 Micro Integrator web page, click Download, provide necessary details, and then click Zip Archive to download the Micro Integrator distribution as a ZIP file.

  2. Extract the ZIP file. The extracted folder will be referred as the <MI_HOME> folder.

Once you have downloaded and set up the Micro Integrator locally, follow the steps given below. Use one of the below two methods.

  1. Click on the Command Palette on the top of the VS Code.

  2. Type > to show the available commands.

  3. Select MI: Add MI server.

  4. Select Add MI server.

  5. Select the folder where <MI_HOME> is located. This wll be set as the current server path.

    Current server path

  6. Run the project.

    Click the Build and Run icon located in the top right corner of the VS Code.

    Build and run

Step 4: Test the use case

You will view the XML message you injected getting printed in the logs of the Micro Integrator every 5 seconds.

   2024-07-17 17:43:06,257]  INFO {AbstractQuartzTaskManager} - Task scheduled: [ESB_TASK][InjectXMLTask].
   [2024-07-17 17:43:06,285]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:07,944]  INFO {AuthenticationHandlerAdapter} - User admin logged in successfully
   [2024-07-17 17:43:11,261]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:16,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:21,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:26,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:31,261]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:36,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:41,257]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:46,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:51,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:43:56,260]  INFO {LogMediator} - City = London
   [2024-07-17 17:44:01,260]  INFO {LogMediator} - City = London
   [2024-07-17 17:44:06,262]  INFO {LogMediator} - City = London
   [2024-07-17 17:44:11,261]  INFO {LogMediator} - City = London