This section explains, through an example scenario, how the Command Message EIP can be implemented using the ESB profile of WSO2 ESBEI. The following topics are covered:
Table of Contents |
---|
...
The Command Message EIP allows you to use messaging to invoke a procedure in another application. For more information, refer to to http://www.eaipatterns.com/CommandMessage.html.
...
Figure 1: Command Message EIP
...
Sample scenario
This example demonstrates how WSO2 the ESB uses profile uses messaging to invoke functionality provided by an application, in this case a 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 profile will pass the message as a document to a sample Axis2 server and invoke the operation directly using the callout the Callout mediator.
The diagram below depicts how to simulate the example scenario using the WSO2 ESB profile.
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) |
---|---|
Sender | Stock Quote Client |
Command Message | Callout Mediatormediator |
Receiver | Stock Quote Service Instance |
Environment setup
- 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.
- 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
...
ESB configuration
Given below is the ESB configuration of this sample. Log in to the Management Console of the ESB profile, click Main, and then click Source View in the Service Bus menu to view this.
Anchor | ||||
---|---|---|---|---|
|
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://ws.apache.org/ns/synapse"> <sequence<proxy name="faultcommand-message-proxy"> <log level startOnLoad="fulltrue"> <property name="MESSAGE" value="Executing default "fault" sequence"/ transports="http https"> <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/><target> <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/> <inSequence> </log> <drop/> </sequence> <sequence name="main"> <callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService" action="urn:getQuote"> <source xmlns:s12s11="http://wwwschemas.w3xmlsoap.org/2003soap/05envelope/soap-envelope" xmlns:s11s12="http://schemaswww.xmlsoapw3.org/2003/05/soap/-envelope/" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]" /> <target xmlns:s12s11="http://wwwschemas.w3xmlsoap.org/2003soap/05envelope/soap-envelope" xmlns:s11s12="http://schemaswww.xmlsoapw3.org/2003/05/soap/-envelope/" xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]" /> </callout> <property name="RESPONSE" value="true"<respond /> <header name="To" action="remove"/> </inSequence> <outSequence> <send/> <respond <drop/> </sequence> </definitions> |
Simulating the sample scenario
...
ant stockquote -Dtrpurl=http://localhost:8280
...
outSequence>
</target>
</proxy>
</definitions> |
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 - 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 expressionsusing xPath expressions.
- target [line 16 in ESB config] target - The target specifies the location where the response should be concatenated.
Simulating the sample scenario
Now, let's try out the sample explained above.
Setting up the environment
Download the Command-Message_1.0.0.zip
, which includes the artifacts of this sample and follow the steps in Setting up the Environment.
Executing the sample
ANT request:
ant stockquote -Dtrpurl=http://localhost:8280/services/command-message-proxy
- 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