Simple Trader Sample Guide for WSO2 Tungsten

Figure:1

INTRODUCTION

We will use this sample to demonstrate the capabilities of Tungsten, highlighting the ease of integration of quality of service modules. In the context of this trading scenario, the use of security and reliable messaging is emphasized on.

Trading on the stock/share market involves three parties-stock exchange, trader (stock broker) & client (shareholder). A shareholder who buys and sells shares on the stock market needs to do so through a stock broker or trader, in which case he would first need to become a client of that particular trader. The shareholder uses his Central Depository System (CDS) account which registers him with the stock exchange to sell & buy shares on the stock market. A trader can register client with the stock exchange.

In this sample we only consider services offered by trader to client for the sake of simplicity & ease of understanding.

The following section describes these services in detail.

SCENARIO

In this sample we only consider the scenario where client gets the stock symbol from the Trader and lists them. Using this symbol client gets stock quotes from Trader.

In summary the services are as follows:

Figure:2

Services offered by Trader to Client

Note: attributes of Stock Quote -name, symbol, selling price, high price, low price

HOW TO BUILD AND RUN THE SAMPLE

SimpleTrader sample is in TUNGSTEN_HOME|samples|SimpleTrader. This sample emulates a simple stock trader, where you can get the stock symbols and the stock quote for a particular stock symbol. In this case the stocks are elements in the periodic table, and their symbols are their chemical element symbols.

To build the samples you need the Apache Ant build tool.

Now follow the simple instructions:

  1. Run WSO2 Tungsten server. See Installation Guide for installation details.
  2. Switch to the SimpleTrader directory, e.g.
  3.   cd TUNGSTEN_HOME\samples\SimpleTrader
  4. From there simply type
  5.   ant

    You should see messages like this:

    Buildfile: build.xml
    clean:
    init:
    
    [mkdir] Created dir: C:\tungsten-\samples\SimpleTrader\temp
    [mkdir] Created dir:
    C:\tungsten-1.0\samples\SimpleTrader\temp\classes
    
    [some lines deleted here]
    
    build-all:
    [echo] Copying the created aar files in to the repository
    [copy] Copying 1 file to C:\tungsten-1.0\repository\services
    
    BUILD SUCCESSFUL
    Total time: 11 seconds

    The build automatically copies the .aar file containing the service into the repository.

  6. If you select the Services page in the Tungsten Management Console. Now you should see the Trader service deployed. If you don't see it, try clicking the 'Services' menu on the right column of the Management Console.
  7. (See Administrator’s Guide on how to sign into Management Console and to navigate through it.)

  8. If you are still in the SimpleTrader directory, you will find the run-client.bat and run-client.sh files. To see the SimpleTrader in action you can use the following syntax on the command prompt.
  9. On MS Windows:

    run-client.bat [ -qos (rm|secure|securerm)] [ -te traderServiceURL]

    On Unix/Linux:

    run-client.sh [ -qos (rm|secure|securerm)] [ -te traderServiceURL]

    Terms used:

    Note: In the secure and securerm cases, in order to enable Username Token Authentication, you must add at least one user and/or role to the Trader service, after engaging the rampart module.

Let’s illustrate the above options with few examples:

Example 1: Without any module engaged.

From SimpleTrader directory type:

   $ sh run-client.sh

You should see:

   Using following as parameters
   TraderService URL : http://localhost:9762/axis2/services/Trader

   STARTING TRADE SAMPLE CLIENT
   =============================
 
   Please select your operation...
   ---------------------------------
   (1) getQuote
   (2) getSymbols
   (3) Exit
 

Example 2: With the rampart module engaged.

From SimpleTrader directory type:

   $ sh run-client.sh -qos secure

You would see a prompt asking for the username and password as follows:

    Using following parameters
    TraderService URL   : http://localhost:9762/axis2/services/Trader
    QOS                 : secure
    STARTING TRADE SAMPLE CLIENT
    =============================

    Enabling UsernameToken authentication...

    Please enter your username :
    test
    Please enter your password :
    test

    Please make sure you enable UsernameToken authentication for the Trader service.
    This can be done by first engaging the security module to the Trader service
    and then assigning a user or a role to the service.

Example 3: With the Sandesha2 module engaged.

From SimpleTrader directory type:

   $ sh run-client.sh -qos rm -te http://127.0.0.1:9762/axis2/services/Trader
        or
        $ sh run-client.sh -qos rm

   Populating the stock market ................Done.
   Using following parameters
   TungstenHome = ../..
   TraderService URL = http://127.0.0.1:9762/axis2/services/Trader
   STARTING TRADE SAMPLE CLIENT
   =============================

   
   Please select your operation...
   ---------------------------------
   (1) getQuote
   (2) getSymbols
   (3) Exit
   :1
   ...Getting Quote...
   Please enter the symbol:mn
   Please select your operation...
   ---------------------------------
   (1) getQuote
   (2) getSymbols
   (3) Exit
   :Printing stock quote...
   mn
   Manganese
   14.0
   28.0
   0.0
   

Example 4: With the Sandesha2 and Rampart modules engaged.

From SimpleTrader directory type:

   $ sh run-client.sh -qos securerm

As you will be able to see, with the rm option, the time to receive the response for the very first request will be comparatively larger. This is due to the control messages that are sent initially, in order to estrablish the reliable messaging channel.

Try playing around with the above options and see how it works for yourself!

Running the Sample with persistent RM

APPENDIX