Versions Compared

Key

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

This section explains, through an example scenario, how the Datatype Channel EIP can be implemented using the WSO2 ESB. The following topics are covered:

Table of Contents

...

This EIP creates a separate channel for each type of data so that all the messages on a given channel will contain the same data type. The sender, who knows the data type, should select the appropriate channel on which to send the message. The receiver knows which identifies the type of data a message contains, based on the channel in which it is received.

For more information, refer to http://www.eaipatterns.com/DatatypeChannel.html.go to Data Type Channel.

Figure 1: Datatype Channel EIP

Example scenario

The example scenario depicts

...

Stock Quote

...

 service deployed in Axis2 server. It offers several service operations to the user.

...

The ESB uses the filter mediator to identify each action that is specified by the sender and diverts the request into the appropriate sequence. Each sequence acts as a separate channel. The sender experiences the decomposition of channels through a log message indicated by

...

the ESB. There will be a different log message for each operation the sender requests.

The diagram below depicts how to simulate the example scenario using

...

the ESB.

Figure 2: Example Scenario scenario of the Datatype Channel EIP

Before digging into implementation details, let's take a look at the relationship between the example scenario and the Datatype Channel EIP by comparing their core components.

Datatype Channel EIP (Figure 1)
Datatype Channel Example Scenario (Figure 2)
SenderClient
Datatype Channel

Filter and Sequence mediators of the ESBthe ESB. The Filter Mediator specifies which the datatype channel to use, and the ESB defines the ESB profile each datatype channel as a Sequence Mediator.

ReceiverStock Quote Server Instance

Environment setup

  1. Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Installation Guide in the WSO2 ESB documentation.
  2. Deploy the SimpleStockQuoteService by starting the Sample Axis2 server on port 9000. For instructions, refer to the section Setting Up the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.

ESB configuration

...

Service

The ESB configuration

Given below is the ESB configuration for simulating the example scenario explained above. 

Anchor
step3
step3

language
Code Block
html/xml
linenumberstrue
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <endpoint name="StockQuoteReceiver">
       <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
   </endpoint>
   <sequence name="MarketActivity">
      <in>
         <log level="custom">
            <property name="MessaginMessaging_Channel" value="MARKET_ACTIVITY"/>
 
       </log>

        <send>
            <endpoint key="StockQuoteReceiver"/>
         </send>
      </in>
      <out>
         <send/>
    
 </out>    </sequence>
   <sequence name="FullQuote">
      <in>          <log level="custom">

           <property name="MessaginMessaging_Channel" value="FULL_QUOTE"/>

        </log>
 
       <send>
            <endpoint key="StockQuoteReceiver"/>
 
       </send>
 
    </in>
      <out>
         <send/>
sequence>

    </out>
   </sequence>
   <sequence name="faultStockQuote">
       <log level="fullcustom">
    
    <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>          <property name="ERRORMessaging_CODEChannel" expressionvalue="get-property('ERROR_CODE')STOCK_QUOTE"/>
         <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/></log>
      </log> <send>
     <drop/>    </sequence>  <endpoint  <sequence namekey="StockQuoteStockQuoteReceiver"/>
      <in> </send>
   </sequence>
   <proxy <log levelname="customdatatype-channel-proxy">
            <property name="Messagin_Channel" value="STOCK_QUOTE"/ startOnLoad="true" transports="http https">
         </log><target>
         <send>             <endpoint key="StockQuoteReceiver"/>
  <log/>
      </send>     <inSequence>
 </in>       <out>          <send/>
      </out>
   </sequence>
   <sequence name="main">
 <switch source="get-property('Action')">
    <log/>       <in>          <filter source="get-property('Action')" <case regex="/*urn:getQuote/*">
    
       <then>                <sequence key="StockQuote"/>
            </then>             <else/></case>
         </filter>          <filter source="get-property('Action')"<case regex="/*urn:getFullQuote/*">
  
         <then>                <sequence key="FullQuote"/>
            </then>             <else/></case>
         </filter>          <filter source="get-property('Action')" <case regex="/*urn:getMarketActivity/*">
    
       <then>                <sequence key="MarketActivity"/>
                   </then>case>
               <else</>switch>
           </filter>inSequence>
          </in> <outSequence>
     <out>          <send<respond/>
           </out>outSequence>
       </target>
   </sequence>proxy>
</definitions>

Simulating the sample scenario

...

ant stockquote -Dtrpurl=http://localhost:8280/ -Dmode=quote

...

How the implementation works 

Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration shown above.

...

The configuration elements

The elements used in the above ESB configuration are explained below.

  • <endpoint> - Defines an endpoint referenced by a name that contains an contains an <address> element with  element with the endpoint address of a particular service. 
  • Sequence [line 5 of the ESB config] <sequence> - The Sequence Mediator defines a sequence block, callable by its key (defined in the name attribute). Each sequence block has its own its own <in> and  and <out> blocks blocks.
  • Sequence main [line 52 of the ESB config] <sequence main> - The main sequence , which that is always run first. 
  • Filter [line 55 of the ESB config] <filter> - A Filter mediator that uses the the get-property XPath expression to find the find the Action field from  field from the SOAP header. The regular expression that is defined in the regex Regex attribute tries to match the value in the Action field. If successfully matched, it calls the relevant sequence by its key. In line 55, if  if get-property('Action') returns  returns urn:getQuote, the  the StockQuote sequence defined  sequence defined in line 39 is called

Simulating the example scenario

Now, let's try out the example scenario explained above.

Setting up the environment

You need to set up the ESB, and the back-end service:

  1. Download the Datatype_1.0.0.zip file, which includes the ESB configuration described above. 
  2. See Setting up the Environment for instructions on setting up the ESB and the back-end service.

Executing the sample

Let's send a request to the ESB using the Stock Quote Client application. Find out more about the Stock Quote Client from the ESB documentation.

  1. Open a new terminal, and navigate to the <ESB_HOME>/samples/axis2Client/ directory. The Stock Quote client application is stored in this directory.
  2. Execute the following command to send the request to the ESB.

    Code Block
    ant stockquote -Dtrpurl=http://localhost:8280/services/datatype-channel-proxy -Dmode=quote

Analyzing the output

When you execute the command above, the ESB first receives the message and then routes it to the back-end service (StockQuoteService). The following output will be printed on the Axis2 server's console: 

Stock Client Console output : 

Standard :: Stock price = $172.81050109499768

Axis2 server console output:

samples.services.SimpleStockQuoteService :: Generating quote for : IBM

ESB Profile logs:

INFO - LogMediator Messaging_Channel = STOCK_QUOTE

Also execute the below commands, and observe the ESB profile log of the corresponding values: STOCK_QUOTE, MARKET_ACTIVITY and FULL_QUOTE.

Notice the following respective output.

Stock Client Console output : 

  • Activity :: Average price = $123.67485145988432

  • Full :: Average price = $125.67875616729333

Axis2 server console output:

  • samples.services.SimpleStockQuoteService :: Generating Market activity report for : [JLN, FDZ, EQR, XNV, RDR, CZC, LIY, ZEP, ZJX, GWO, STS, NQU, RMA, UUR, PFL, ZEF, IYU, ZLV, KTW, PUN, IOZ, PZJ, HAE, PSL, CQM, CLX, BWI, UYF, QWC, EKB, LMM, UQI, GZA, KRC, GFB, DWM, ETA, SRS, VEP, ZTS, TNE, FJF, LNV, QBY, ZIO, HBS, IIW, SNO, MMO, BTY, OGJ, OUW, CLW, OZT, MXB, HNK, FQC, VEI, BLD, LUP, PHR, JUQ, MZM, GIL, EVE, UAH, SHV, WYS, MAG, XBX, ZYB, MUX, MUO, DAM, DVR, RDF, LGB, KGS, DWP, ZAG, SDF, BSF, CTX, MKG, YTO, RRX, OVJ, MEZ, ODU, JGU, GQB, SLW, UCQ, GDI, DIO, BKV, UUQ, JES, TAZ, AAU]
  • samples.services.SimpleStockQuoteService :: Full quote for : IBM

ESB Profile logs:


    • INFO - LogMediator Messaging_Channel = MARKET_ACTIVITY

    • INFO - LogMediator Messaging_Channel = FULL_QUOTE