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.
-
Launch VS Code with the Micro Integrator extension installed.
-
Click on the Micro Integrator 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 the Sequence¶
-
Navigate to the MI Project Explorer > Sequences.
-
Hover over Sequences and click the + icon that appears.
-
In the Sequence Form that appears, provide
InjectXMLSequence
as the Name. -
Click Create. Then you will be directed to the MI Overview page.
-
Click on
InjectXMLSequence
under Sequences that you have just created to open its diagram view. -
Next, add a Log mediator to the sequence. Click the + icon and select Log mediator from the Palette under Mediators > Generic.
-
Enter the following details in the Log details pane.
- Log Category:
INFO
- Log Level:
CUSTOM
- Log Category:
-
Under Properties, click Add Parameter to add a new property with the following details:
Property Description Property Name City
Property Value //city
-
Click on
EX
to set the value to the expression type. -
Click Save to save the properties.
-
Click Submit to save the Log details.
-
Next, add the Drop mediator. Click on the + icon and select Drop mediator from Mediators > Generic.
-
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¶
-
Navigate to the MI Project Explorer > Tasks.
-
Hover over Tasks and click the + icon that appears.
-
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>
- Task Name:
-
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:
-
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.
-
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.
-
Click on the Command Palette on the top of the VS Code.
-
Type
>
to show the available commands. -
Select MI: Add MI server.
-
Select Add MI server.
-
Select the folder where
<MI_HOME>
is located. This wll be set as the current server path. -
Run the project.
Click the Build and Run icon located in the top right corner of the VS Code.
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