The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation. "> The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 41 Next »

The Message Router EIP reads the content of a message and routes it to a specific recipient based on its content. When the implementation of a specific logical function is distributed across multiple physical systems, an incoming request needs to be passed on to the correct service based on the content of the request. A Message Router is useful in handling such scenarios.

The Message Router performs a logical function (such as an inventory check). It receives a request message (new order), reads it, and routes the request to one of the two recipients according to the content of the message. The router is also defined as a special type of a filter.

For more information, go to Message Router.

The following sections explain how you can implement a sample scenario of this EIP using the ESB profile of WSO2 EI. 

Sample scenario

The sample scenario depicts an inventory for stocks, and how Message Router EIP routes a message to a different service based on the content of the message. When the router receives a stock request, it reads the content of the request as follows.

  • If the request is made to foo, it is routed to fooOutQueue
  • If the request is for bar, it is routed to barOutQueue.

The Switch and Send mediators of the ESB profile of WSO2 EI simulate the Message Router EIP. The Switch Mediator depicts the Router and observes the content of the message, while the Send Mediator sends the message to a selected recipient.

Each case defined in the Switch mediator is used to decide the routing of the message to the appropriate service. fooOutQueue and barOutQueue act as two separate services.


 The Synapse configurations of the artifacts

When you unzip the ZIP file you download below in Step 6 when simulating the sample scenario, you can find the below configurations in the <UNZIPPED_FILE>/src/main/synapse-config directory. For more information about these artifacts, go to WSO2 EI Documentation.

Simulating the sample scenario

Follow the below instructions to simulate this sample scenario.

Setting up the environment

Download the Message-Router_1.0.0.zip file, which includes the artifacts of this sample and follow the steps in  Setting up the Environment, to set up the environment.

You need to start two instances of the Axis2 server to run in ports 9000 and 9001 by executing the following commands:

  • ./axis2server.sh -http  9000 -https  9002 -name MyServer1
  • ./axis2server.sh -http  9001 -https  9003 -name MyServer2

Executing the sample

In the Terminal, navigate to the <EI_HOME>/samples/axis2Client/ directory, and execute the following command to send a request using the Stock Quote Client to the ESB profile: 

ant stockquote -Dtrpurl=http://localhost:8280/services/message-router-proxy -Dsymbol=foo

For information on the Stock Quote Client and its operation modes, go to Stock Quote Client in the WSO2 EI Documentation.

The structure of the request is as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
   <soapenv:Header>    
   </soapenv:Header> 
   <soapenv:Body>
        <ser:getQuote>         
         <ser:request>
             <ser:symbol>foo</ser:symbol>
         </ser:request>       
      </ser:getQuote>
   </soapenv:Body>
</soapenv:Envelope>

Analyzing the result

After you execute the above command through the client, observe that the request is transferred to foo inventory service. Notice the following processed server log in the Stock Quote Client console: 

Standard :: Stock price = $77.86763451813164

Change the -Dsymbol parameter to bar and run the folloiwng command:

ant stockquote -Dtrpurl=http://localhost:8280/services/message-router-proxy -Dsymbol=bar

Now, the request goes to bar inventory service. Notice the following processed server log in the Stock Quote Client console: 

Standard :: Stock price = $64.81823486260222

  • No labels