WSO2 ESB - Tasks Samples

Running the Tasks samples with WSO2 Enterprise Service Bus (ESB)

Sample 300: Introduction to tasks with simple trigger

<definitions xmlns="http://ws.apache.org/ns/synapse">

        <task class="org.apache.synapse.startup.tasks.MessageInjector" 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">
                    <m0:request>
                        <m0:symbol>IBM</m0:symbol>
                    </m0:request>
                </m0:getQuote>
            </property>
            <trigger interval="5"/>
        </task>

        <in>
            <send/>
        </in>
        <out>
            <log level="custom">
                <property name="Stock_Quote_on" expression="//ns:return/ax21:lastTradeTimestamp/child::text()" xmlns:ax21="http://services.samples/xsd" xmlns:ns="http://services.samples"/>
                <property name="For_the_organization" expression="//ns:return/ax21:name/child::text()" xmlns:ax21="http://services.samples/xsd" xmlns:ns="http://services.samples"/>
                <property name="Last_Value" expression="//ns:return/ax21:last/child::text()" xmlns:ax21="http://services.samples/xsd" xmlns:ns="http://services.samples"/>
            </log>
        </out>

    </definitions>

Objective: Introduce the concept of tasks and how simple trigger works

Prerequisites:
You will need access to build the SimpleStockQuoteService as mentioned in the above and start the sample axis2 server before staring ESB.

When ever ESB gets started with this configuration (i.e. ./wso2esb-samples -sn 300), this task will run periodically in 5 second intervals. You could limit the number of times that you want to run this task by adding a count attribute with an integer as the value, if the count is not present as in this sample this task will run forever.

One can write his own task class implementing the org.apache.synapse.startup.Task interface and implementing the execute method to do the task. For this particular sample we have used the MessageInjector which just injects a message specified into the ESB environment.