Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Having deployed a task implementation to the ESB runtime (see Writing Tasks), you can use the ESB Management Console to add a task to the "Tasks" list and schedule various instances of the task. You can use either UI configuration  or XML configuration to add and schedule tasks.

...

Anchor
UI configuration
UI configuration

UI Configuration

Follow the instructions below to add and schedule a task in ESB Management Console.

...

9. Click Schedule to apply the settings.

...

Anchor
XML configuration
XML configuration

XML Configuration

Follow the instructions below to add and schedule tasks using XML configuration.

...

3. In the "Manage" menu, click on "Source View" under "Service Bus."

4. Add a necessary piece of code to "Service Bus Configuration." In the source view, add the task configuration based on your requirement.

The syntax of the task configuration is as follows:

Code Block
<task class="string" name="string" [group="string"] [pinnedServers="(serverName)+"]>
       <property name="string" value="String"/>
       <property name="string"><somexml>config</somexml></property>
       <trigger ([[count="int"]? interval="int"] | [cron="string"] | [once=(true | false)])/>
</task>

...

Anchor
examples
examples

Examples 

Following are examples of configuring some common use cases. For an example of configuring a task with a simple trigger, see Sample 300: Introduction to Tasks with Simple Trigger. To see a complete example of writing a new task and configuring it in the UI, see Writing Tasks Sample.

Anchor
interval
interval

To run every 5 seconds continuously: Anchorintervalinterval

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

To

Anchor
specified number of times
specified number of times

To run every 5 seconds for 10 times:  Anchorspecified number of timesspecified number of times

Code Block
<task name="CheckPrice" class="org.wso2.esb.tutorial.tasks.PlaceStockOrderTask">
<trigger interval="50005" count="10"/>
</task>

Anchor
cron style
cron style

You can also give cron-style values. To run daily at 1:30 AM: Anchorcron stylecron style

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

Anchor
once
once

To run only once after ESB starts: Anchoronceonce

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

Anchor
inject
inject

Injecting the message to a named sequence or proxy service 

...

By default, the message is sent to the Main sequence. To send it to a different sequence or to a proxy service, set the injectTo property to sequence or proxy, and then add the sequenceName or proxyName property to specify the name of the sequence or proxy service to use. For example:

...

Code Block
languagehtml/xml
titleInjecting to a proxy service
 <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>

 

Anchor
inject
inject

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.

...