Scheduled Task Properties

Introduction

WSO2 Micro Integrator can be configured to execute tasks periodically. According to the default task scheduling implementation in WSO2 Micro Integrator, a task can be configured to inject messages, either to a defined endpoint, to a proxy service, or a specific sequence. If required, you can use a custom task scheduling implementation.

You can schedule a task to run after a time interval of 't' for an 'n' number of times, or you can schedule the task to run once when the server starts. Alternatively, you can use CRON expressions to have more control over how the task should be scheduled. For example, you can use a CRON expression to schedule the task to run at 10 pm on the 20th day of every month.

Properties

See the topics given below for the list of properties that can be configured when you create a Scheduled Task.

Required Properties

The following properties are required when creating a scheduled task.

Parameter Description
Task Name Name of a scheduled task.
Task Group The synapse.simple.quartz group will be selected by default.
Task Implementation The default task implementation class ( org.apache.synapse.startup.tasks.MessageInjector ) of the Micro Integrator will be selected by default. This class simply injects a specified message into the Synapse environment when the server starts.
If you are want to use a custom task implementation, see the instructions on writing tasks .
Trigger Type

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 the Micro Integrator starts:

    <task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask">
        <trigger once="true"/>
        </task>

    To run every 5 seconds continuously:

    <task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask">
        <trigger interval="5"/>
        </task>

    To run every 5 seconds for 10 times:

    <task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask">
        <trigger interval="5" count="10"/>
        </task>
  • Cron Trigger: Schedules the task according to a Cron expression. See the following example for acron trigger where the task is scheduled to run at 1:30 AM:

    <task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask">
        <trigger cron="0 30 1 * * ?"/>
        </task>
Pinned Servers

The list of Micro Integrator server nodes that will run the task. You can specify the IP addresses of the required nodes.

Note:

This setting can be used if you want the task to run on a selected set of nodes in a product 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.

Task Implementation Properties

Listed below are the optional task implementation properties you can use when creating a scheduled task.

Parameter Name Description
message

Specify the body of the request that should be sent when the task is executed.

Note:

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:

<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="CheckPrice">        <property name="to" value="http://localhost:9000/services/SimpleStockQuoteService"/>
            <property name="soapAction" value="urn:getQuote"/>
            <property name="message">
                <m0:getQuote xmlns:m0="http://services.samples" xmlns="http://ws.apache.org/ns/synapse">
                    <m0:request>
                        <m0:symbol>IBM</m0:symbol>
                    </m0:request>
                </m0:getQuote>
            </property>
            <trigger interval="5"/>
        </task>
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:

<task name="SampleInjectToSequenceTask"
             class="org.apache.synapse.startup.tasks.MessageInjector"
             group="synapse.simple.quartz">
          <trigger count="2" interval="5"/>
    
          <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="message">
             <m0:getQuote xmlns:m0="http://services.samples">
                <m0:request>
                   <m0:symbol>IBM</m0:symbol>
                </m0:request>
             </m0:getQuote>
          </property>
    
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
    
                    name="sequenceName"
                    value="SampleSequence"/>
    
       </task>
proxyName

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:

 <task name="SampleInjectToProxyTask"
             class="org.apache.synapse.startup.tasks.MessageInjector"
             group="synapse.simple.quartz">
          <trigger count="2" interval="5"/>
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks" name="message">
             <m0:getQuote xmlns:m0="http://services.samples">
                <m0:request>
                   <m0:symbol>IBM</m0:symbol>
                </m0:request>
             </m0:getQuote>
          </property>
    
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
    
                    name="proxyName"
                    value="SampleProxy"/>
    
          <property xmlns:task="http://www.wso2.org/products/wso2commons/tasks"
                    
                    name="injectTo"
                    value="proxy"/>
    
       </task>
Top