[Download] | [Documentation Home] | [Release Note]
When using data services, we may come across requirements where, when a certain action is done; such as invoking an operation with certain arguments or a specific response is returned, in that situation, we would like to trigger an event to notify of such actions. This is accomplished in WSO2 Data Services Server using input and output event triggers.
The sample data service "EventingSample" should be deployed as per the instructions mentioned in Deploying Samples section.
In the sample, we are defining a specific topic for events to be published, and an email address is added as a subscription for that topic. In order to allow mail to be sent, we have to configure the mail sender in the client Axis2 configuration. A sample axis2.xml for the client configuration is stored at CARBON_HOME/samples/resources/sample_axis2_client.xml. Use the aforementioned file to replace the CARBON_HOME/repository/conf/axis2_client.xml file, now the axis2_client.xml will contain an already configured mail sender section and is ready to be used.
Here we will use the XML Edit option to edit the dataservice. In the XML view, replace all the occurences of "test@test.com" with your own email address.
After the above changes are done, restart the server.
The sample service can be run using the "tryit" tool, which is bundled with WSO2 Data Services Server.
The service is based around the functionality of managing the inventory of a car/motorcycle dealership. It contain the following queries.
We will first add a new product into the inventory. This is shown in Figure 1.
Figure 1: Adding new product.
After adding the product, we will update the availability of it by changing the product quantity in stock.
Figure 2: Updating product stock.
Here we are setting the "quantityInStock" to 5, and because of the event trigger, when the stock is less than 10, an event is fired, which will be the case here.
Soon you will receive an event notification to your mail inbox. Figure 3 shows the contents of the email attachment that will be received.
Figure 3: Input event trigger notification content.
Here we are querying the inventory system for a specific motorcycle model.
Figure 4: Querying an item.
By making a request with the motorcycle product line, we are triggering an event associated with it, and an email will be sent regarding this query. The contents of the email is shown below in Figure 5.
Figure 5: Output event trigger notification content.