/
Document Message

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.

Document Message

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

Introduction to Document Message

The Document Message EIP is used to reliably transfer a data structure between applications. TheĀ Command Message EIPĀ allows you to invoke only a specific client through the ESB, while the Document Message EIP sends the entire data unit to the receiver. For more information, seeĀ http://www.eaipatterns.com/DocumentMessage.html.

Figure 1: Document Message EIP

Example scenario

This example demonstrates how the ESB transmits an entire message from a client to a sampleĀ Axis2 server as a document message. Then theĀ Axis2 server processes the message and identifies which operation to invoke.

The following diagram depicts this process.

Figure 2: Example scenario of the Document Message EIP

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

Document Message EIP (Figure 1)Document Message Example Scenario (Figure 2)
SenderStock Quote ClientĀ 
Document MessageProxy Service
ReceiverSimple Stock 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="DocumentMessageProxy" transports="https http" startOnLoad="true" trace="disable">
      <target>
         <inSequence>
            <send>
               <endpoint>
                  <address uri="http://localhost:9000/services/SimpleStockQuoteService" />
               </endpoint>
            </send>
         </inSequence>
         <outSequence>
            <send />
         </outSequence>
      </target>
   </proxy>
</definitions>

The configuration elements

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

  • Proxy ServiceĀ - The proxy service takes a request and forwards it to the back-end service, abstracting the routing logic from the client. In this example scenario, the proxy service just forwards the request to the back-end service, following the Document Message EIP.Ā 

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Ā Document-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.

    When you set up the environment, note that you only need to start one instance of the back-end service (Stock Quote Service) to simulate this example.

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/DocumentMessageProxy

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:Ā 

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

The generated stock quote will then be sent to the client application (Stock Quote Client). The following output will be printed on the client application's console:

Standard :: Stock price = $72.42070059233666