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.

...

  • format - defines the format of the message similar to Address Endpoint formats: soap11, soap12, pox, get
  • message  - you can provide an XML or literal value depending on message format. 

    Note
    titleNote

    When adding you add a scheduled task, 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 - specify the SOAP Action to use when sending the message to the endpoint. 
  • to - specify the endpoint address. 
  • injectTo - specify whether to inject a message to a proxy service or sequence. This field takes values 'sequence' or 'proxy' and 'main' to inject to main sequence. 
  • proxyName - if injectTo contains 'proxy' then the name of the proxy to inject the message to is specified here. 
  • sequenceName - if injectTo contains 'sequence' then the name of the sequence to inject the message to is specified here. 

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 run every 5 seconds for 10 times: 

Anchor
specified number of times
specified number of times

To run every 5 seconds for 10 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.

...