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

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

Introduction to Splitter

The Splitter EIP processes messages containing multiple elements that might have to be processed in different ways. The Splitter breaks out the composite message into a series of individual messages, each containing data related to one item. For more information, refer to http://www.eaipatterns.com/Sequencer.html.

Figure 1: Splitter EIP

Example scenario

This example demonstrates WSO2 ESB implementing the Splitter EIP by processing a list of repeating elements, each of which will be processed individually. The client sends multiple requests in a single message. Using the Iterate Mediator of the ESB, each request will be processed individually and transmitted to a sample Axis2 server.

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

Figure 2: Splitter Example Scenario

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

Figure 1: Splitter EIPFigure 2: Splitter Example Scenario
New Order RequestStock Quote Request
SplitterIterate Mediator
Order Item RequestEndpoint

Environment setup

  1. Download an install the WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Getting Started in the WSO2 ESB documentation.
  2. Start a Sample Axis2 server instance. For instructions, refer to section ESB Samples Setup - Starting Sample Back-End Services 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 Main Menu, click Service Bus and then Source View. 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">
   <proxy name="SplitMessageProxy" transports="http https" startOnLoad="true">
      <target>
         <inSequence>
            <log level="full"/>
            <iterate xmlns:m0="http://services.samples"
                     preservePayload="true"
                     attachPath="//m0:getQuote"
                     expression="//m0:getQuote/m0:request">
               <target>
                  <sequence>
                     <send>
                        <endpoint>
                           <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                        </endpoint>
                     </send>
                  </sequence>
               </target>
            </iterate>
         </inSequence>
         <outSequence>
            <drop/>
         </outSequence>
      </target>
      <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
   </proxy>
   <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">
      <in/>
      <out/>
   </sequence>
</definitions>

Simulating the sample scenario

Send the following request to the ESB server using a tool like SOAP UI.

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

Note that the three requests will appear as sent in the Axis2 server log.

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 illustrated in step 3 above.

  • iterate [line 7 in ESB config] - The Iterate mediator takes each child element of the element specified in its xPath expression, and applies the sequence flow inside the iterator mediator. In this example, it takes each getQuote request specified in the incoming request to the ESB, and forwards this request to the target endpoint. 
  • No labels