com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Scheduling a Task Using the Default Implementation

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

  1. Open WSO2 Integration Studio and click ESB Project → Create New in the Getting Started tab as shown below.

  2. Enter ScheduleDefaultTask as the ESB Project Name and click Finish.

  3. The new project will be listed in the project explorer.

Creating the Sequence

  1. In the Project Explorer, right click the ScheduleDefaultTask project, and click New → Sequence.
  2. Click Create New Sequence and click Next.
  3. Enter the InjectXMLSequence as the sequence name and click Finish.
     
  4. Drag and drop a Log mediator and a Drop mediator from the Mediators Palette.
     
  5. Click on the Log mediator, and in the Properties section enter the following details.
    • Log Category: INFO
    • Log Level: CUSTOM 
     Configuration of the Sequence

    The below is the complete source configuration of the Sequence (i.e., the InjectXMLSequence.xml file).

    <?xml version="1.0" encoding="UTF-8"?>
    <sequence name="ScheduleCustomSequence" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
        <log level="custom" />
        <drop />
    </sequence>

Creating the Scheduled Task

  1. Right click the ScheduleDefaultTask project and click New → Scheduled Task.
  2. 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.

  3. Enter the below details and click Finish.
    • Task Name: InjectXMLTask
    • Count: -1
    • Interval (in seconds): 5

     More information of the above parameters
    ParameterDescription
    Task NameName of a scheduled task.
    Task GroupThe synapse.simple.quartz group will be selected by default.
    Task ImplementationThe 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.
    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:

    • 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 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  InjectXMLTask created task created in the src/main/synapse-config/tasks directory under the ScheduleDefaultTask project. 

Defining the properties of the Task

  1. In the Form View of the InjectXMLTask.xml file, click the Task Implementation Properties button.
  2. Select XML as the Parameter Type of the message parameter, enter <abc>This is a scheduled task of the default implementation.</abc> as the XML message in the Value/Expression field and click OK.

     More information on the above properties
    Parameter NameDescription
    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. 

    soapActionThis 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>
    injectToIf 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>

    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

    The below is the complete source configuration of the Scheduled Task (i.e., the InjectXMLTask.xml file).

    <?xml version="1.0" encoding="UTF-8"?>
    <task class="com.example.post.scheduleTask1.ESBTask" group="synapse.simple.quartz" name="PrintParameterTask" xmlns="http://ws.apache.org/ns/synapse">
        <trigger interval="5" />
        <property name="parameter" value="<abc>This is a scheduled task of the default implementation.</abc>" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
    </task>

Deploying the Task

  1. Open the pom.xml file of the Composite Application Project and select the artifacts that need to be deployed.
  2. 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.

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.