According to the default task implementation in the ESB profile, a task can be configured to inject messages, either to a defined endpoint, to a proxy service or a specific sequence defined in the ESB. The sections below demonstrate an example of scheduling a task using the default implementation, to inject an XML message and to print it in the logs of the server.
Creating the Task
Follow the steps below to create the task, which you want to schedule.
Creating the ESB Project
Open WSO2 Integration Studio and click ESB Project → Create New in the Getting Started tab as shown below.
Enter ScheduleDefaultTask as the ESB Project Name and click Finish.
- The new project will be listed in the project explorer.
Creating the Sequence
- In the Project Explorer, right click the ScheduleDefaultTask project, and click New → Sequence.
- Click Create New Sequence and click Next. This is the sequence that the task will trigger.
- Enter the InjectXMLSequence as the sequence name and click Finish.
- Drag and drop a Log mediator and a Drop mediator from the Mediators Palette.
- Click on the Log mediator, and in the Properties section enter the following details.
Configuration of the Sequence
- Log Category:
- Log Level:
The below is the complete source configuration of the Sequence (i.e., the
- Log Category:
Creating the Scheduled Task
- Right click the ScheduleDefaultTask project and click New → Scheduled Task.
Select Create a New Scheduled Task Artifact and click Next.
Importing a task?
If you already have a task created, you have the option of importing the XML configuration. Select Import Scheduled Task Artifact and follow the instructions on the UI. To create a new task from scratch, continue with the following steps.
- Enter the below details and click Finish.
More information of the above parameters
- Task Name:
- Interval (in seconds): 5
Parameter Description Task Name Name of a scheduled task. Task Group The
synapse.simple.quartzgroup will be selected by default.
Task Implementation The default task implementation class (
org.apache.synapse.startup.tasks.MessageInjector) of the ESB will be selected by default. This class simply injects a specified message into the Synapse environment of the ESB when the server starts.
If you are want to use a custom task implementation, see the instructions in Writing Tasks.
The trigger type determines the task execution schedule.
Simple Trigger: Schedules the task to run a specified number of times at specified intervals. In the Count field, enter the number of time the task should be executed, and in the Interval field, enter the time interval (in seconds) between consecutive executions of the task.
See the following examples for simple triggers:
To run only once after WSO2 EI starts:
To run every 5 seconds continuously:
To run every 5 seconds for 10 times:
The list of ESB server nodes that will run the task. You can specify the IP addresses of the required nodes.
This setting can be used if you want the task to run on a selected set of nodes in an ESB cluster. Note that the task will only run on one of the nodes at a time. It will fail over to another node, only if the first node fails. Pinned servers will override the default task handling behavior defined at server-level (for this particular task). However, if rule-based task handling is specified at server-level, you need to ensure that the same server nodes you specify as pinned servers for the task are also specified for the task handling rule at server-level.
In the Package Explorer, you view the
InjectXMLTaskcreated task created in the
src/main/synapse-config/tasksdirectory under the ScheduleDefaultTask project.
- Task Name:
Defining the properties of the Task
- In the Form View of the
InjectXMLTask.xmlfile, click the Task Implementation Properties button.
Select XML as the parameter type of the message parameter and enter
<abc>This is a scheduled task of the default implementation.</abc>as the XML message in the Value/Expression field.
Also, specify Sequence as the parameter type of the injectTo parameter and fill in the sequence name, which was created above (InjectXMLSequence.xml).
Click OK to create the task property.More information on the above properties
Parameter Name Description message
Specify the body of the request that should be sent when the task is executed.
It is mandatory to provide a value for the message property. Therefore, even If you do not want to send a message body, you have to provide an empty payload as the value to avoid an exception being thrown.
soapAction This is the SOAP action to use when sending the message to the endpoint. to
If the task should send the message directly to the endpoint through the main sequence, the endpoint address should be specified. For example, if the address of the endpoint is http://localhost:9000/services/SimpleStockQuoteService, the Synapse configuration of the scheduled task will be as follows:
injectTo If the task is not sending the message directly to the endpoint (through the main sequence), it should be injected to proxy service or a sequence. Specify sequence, or proxy. sequenceName
If the task should inject the message to a sequence (injectTo parameter is sequence), enter the name of the sequence. For example, if the name of the sequence is 'SampleSequence', the synapse configuration of the scheduled task will be as follows:
If the task should inject the message to a proxy service (injectTo parameter is proxy), enter the name of the proxy service. For example, if the name of the proxy service is 'SampleProxy', the synapse configuration of the scheduled task will be as follows:
Injecting messages to RESTful Endpoints
In order to use the Message Injector to inject a message to a RESTful endpint, we can specify the injector with the required payload and inject the message to sequence or proxy service as defined above. The sample below shows a RESTful message injection through a ProxyService.Configuration of the Scheduled Task
Below is the complete source configuration of the Scheduled Task (i.e., the
Deploying the Task
- Open the
pom.xmlfile of the Composite Application Project and select the artifacts that need to be deployed.
- Start the ESB profile by adding the ScheduleDefaultTaskCompositeApplication. For instructions, see Running the ESB profile via WSO2 Integration Studio.
Viewing the output
You view the XML message you injected (i.e.,
<abc>This is a scheduled task of the default implementation.</abc>) getting printed in the logs of the ESB Profile every 5 seconds.