You may come across a requirement to trigger an event to notify of an action when a certain action is done, such as invoking an operation with certain arguments or when a specific response is returned. This is accomplished in the WSO2 Data Services Server using input and output event triggers.
The sample data servic e EventingSample should be deployed using the instructions in Deploying Data Services section.
In the sample, we define a specific topic for events to be published, and an email address is added as a subscription for that topic. In order to allow mails to be sent, we have to configure the mail sender in the client Axis2 configuration. A sample axis2.xml file for the client configuration is stored at CARBON_HOME/samples/resources/sample_axis2_client.xml. Use it to replace the CARBON_HOME/repository/conf/axis2/axis2_client.xml file. The axis2_client.xml contains an already configured mail sender section and is ready to be used.
Here we use the XML Edit option to edit the dataservice. In the XML view, replace all occurences of "[email protected]" with your own email address and restart the server.
The sample service can be run using the TryIt tool, which is bundled with the WSO2 Data Services Server, or a code-generated java client sample as discussed in the section.
The service is based on the functionality of managing the inventory of a car/motorcycle dealership. It contain the following queries.
Sample run of the service using the TryIt tool is shown below.
We will first add a new product into the inventory.
After adding the product, we will update the availability of it by changing the product quantity in stock.
Here we are setting the "quantityInStock" to 5. Because of the event trigger, when the stock is less than 10, an event is fired. Soon you will receive an event notification to your mail inbox. Figure below shows the contents of the email attachment.
Here we are querying the inventory system for a specific motorcycle model.
By making a request with the motorcycle product line, we are triggering an event associated with it. An email will be sent regarding this query. The contents of the email is as follows: