Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel3
minLevel3

Introduction

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.

Table of Contents
maxLevel3
minLevel3

About the sample data service

The service is based on the functionality of managing the inventory of a car/motorcycle dealership. It contain the following queries.

  • addProductQuery: This query adds a new product to the catalog.
  • updateProductQuantityQuery: This query updates the availability of a certain product. This is linked with an input event trigger, which monitors if the stock of this product is critically low. If so, if fires an event notifying the subscribers that this product's stock needs to be updated.
  • getProductByCodeQuery: This query retrieves product information, given the product code. The company gives special attention to people querying the database for motocycles. So when a query is made where the product type is a motorcyle, an output trigger associated with this query is triggers and a message is sent to the respective subscribers which is our email address in this case.

Building the sample

The sample data servic e EventingSample should be deployed using the instructions in Samples Setup section.

...

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 Data Services Clients section.

Service description

The service is based on the functionality of managing the inventory of a car/motorcycle dealership. It contain the following queries.

  • addProductQuery: This query adds a new product to the catalog.
  • updateProductQuantityQuery: This query updates the availability of a certain product. This is linked with an input event trigger, which monitors if the stock of this product is critically low. If so, if fires an event notifying the subscribers that this product's stock needs to be updated.
  • getProductByCodeQuery: This query retrieves product information, given the product code. The company gives special attention to people querying the database for motocycles. So when a query is made where the product type is a motorcyle, an output trigger associated with this query is triggers and a message is sent to the respective subscribers which is our email address in this case.
Sample run

Sample run of the service using the TryIt tool is Follow the steps below to demonstrate this functionality using the TryIt tool:

  1. Log in to the management console of your server and click List under Services in the navigator. The CSVSampleService will be listed here.
  2. Click Try this service to open the TryIt tool.
  3. Select the relevant operation and click Send to execute the command as shown below.
    • We will first add a new product into the inventory

...

    • by executing the "addProduct" operation:
      Image Modified 
    • After adding the product, we will update the availability of it by changing the product quantity in stock. Execute the "updateProductQuantity" operation:
      Image Modified

...

    •  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.
      Image Modified 
    • Here we are querying the inventory system for a specific motorcycle model by executing the "getProductByCode" operation.
      Image Modified

...

    • 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:
      Image Modified