The following steps explain the process of creating and scheduling a custom task implementation:
Step 1. Write the Task Class
The custom Task class should implement
org.apache.synapse.startup.Task. Each task should therefore implement the
Task interface. This interface has a single
execute() method. This method contains the code that is to be run at the specified intervals.
execute() method contains following actions:
- Check whether the file exists at the desired location.
- If it does, then read the file line by line composing place order messages for each line in the text file.
- Individual messages are then injected to the synapse environment with the given
- Set each message as
OUT_ONLYsince it is not expected any response for messages.
In addition to the
execute() method, it is also possible to make the class implement a
JavaBean interface. The WSO2 EI console can then be used to configure the properties of this
Step 2. Customize the Task
It is possible to pass values to a task at run time using property elements. When creating a
Task object, WSO2 EI will initialize the properties with the given values in the configuration file. For those properties given as XML elements, properties need to be defined within the
Task class using the following format:
It can be initialized with an XML element as follows:
Step 3. Compile and bundle the task
Assemble the compiled class
Task as a JAR file.
Step 4. Add to the WSO2 EI Class Path
After compiling and bundling the
Task class, you need to add it to the WSO2 EI class path. Place the JAR file in the
lib directory of WSO2 EI.
Task class will be available for use from the next time you start WSO2 EI.
It is required to restart WSO2 EI for the JAR containing the task implementation to be picked up by the server runtime. An OSGi bundle containing the task implementation will be created automatically and it will be deployed in the server.
Step 5. Configure and Schedule in WSO2 EI Console
For more information see http://wso2.org/library/2900.