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

This section explains, through an example scenario, how the Command Message EIP can be implemented using 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 WSO2 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 WSO2 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 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. Start the sample Axis2 server. For instructions, refer to the section Setting Up the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.

ESB configuration

Start the ESB server and log into its management console UI (https://localhost:9443/carbon). In the management console, navigate to the Main menu and click Source View in the Service Bus section. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.

<definitions xmlns="http://ws.apache.org/ns/synapse">
   <sequence name="fault">
      <log level="full">
         <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>
         <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
         <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
      </log>
      <drop/>
   </sequence>
   <sequence name="main">
      <callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService"
               action="urn:getQuote">
         <source xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
                 xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
         <target xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
                 xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
                 xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
      </callout>
      <property name="RESPONSE" value="true"/>
      <header name="To" action="remove"/>
      <send/>
      <drop/>
   </sequence>
</definitions>

Simulating the sample scenario

  1. Send a request using the Stock Quote client to WSO2 ESB in the following manner. Information about the Stock Quote client and its operation modes are discussed in the Sample Clients section in the WSO2 ESB documentation.

    ant stockquote -Dtrpurl=http://localhost:8280
  2. The client receives the stock quote as the response. 

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. 

  • callout [line 11 in ESB config] - The callout mediator specifies a particular method to invoke in the back-end service. This invocation is blocking.  
  • source [line 13 in ESB config] - The source specifies the payload for the method invocation using xPath expressions. 
  • target [line 16 in ESB config] - The target specifies the location where the response should be concatenated.
  • No labels