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 22 Next »

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

Introduction to Command Message

The Command Message EIP allows you to use messaging to invoke a procedure in another application. For more information, refer to http://www.eaipatterns.com/CommandMessage.html.

Figure 1: Command Message EIP

Example scenario

This example demonstrates how the ESB uses messaging to invoke functionality provided by an application, in this case a stock quote service. A command message can be in any form, including a JMS serialized object or a text message in the form of an XML or SOAP request. In this example, the ESB will pass the message as a document to a sample Axis2 server and invoke the operation directly using the Callout mediator.

The diagram below depicts how to simulate the example scenario using the ESB.

Figure 2: Example scenario of the Command Message EIP

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

Command Message EIP (Figure 1)Command Message Example Scenario (Figure 2)
SenderStock Quote Client
Command MessageCallout mediator
ReceiverStock Quote Service

The ESB configuration

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

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <proxy name="command-message-proxy" startOnLoad="true" transports="http https">
      <target>
         <inSequence>
             <callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService" action="urn:getQuote">
         <source xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]" />
         <target xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]" />
      </callout>
      <respond />
         </inSequence>
         <outSequence>
            <respond />
         </outSequence>
      </target>
   </proxy>
</definitions>

The configuration elements

Let's investigate the elements of the configuration in detail.

  • <callout> - The callout mediator specifies a particular method to invoke in the back-end service. This invocation is blocking.  
  • <source> - The source specifies the payload for the method invocation using xPath expressions. 
  • <target> - The target specifies the location where the response should be concatenated.

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 Command-Message_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.

    ant stockquote -Dtrpurl=http://localhost:8280/services/command-message-proxy

Analyzing the output

The client receives the stock quote as the response. 
Stock Quote Client response: 

Standard :: Stock price = $85.09378162206208

Axis2 server response: 

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

  • No labels