Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

Table of Contents

...

  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 three sample Axis2 server instances on ports 9000, 9001, and 9002. For instructions, refer to the section Setting Upp the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.

...

Code Block
languagehtml/xml
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?> 
<definitions xmlns="http://ws.apache.org/ns/synapse">
  <proxy xmlns="http://ws.apache.org/ns/synapse" name="ScatterGatherProxy" transports="https http" startOnLoad="true" trace="disable">  
      <description/>  
      <target>  
          <inSequence>  
              <clone>  
                  <target>  
                      <endpoint name="vendorA">  
                          <address uri="http://localhost:9000/services/SimpleStockQuoteService/"/>  
                      </endpoint>  
                  </target>  
                  <target>  
                      <endpoint name="vendorB">  
                          <address uri="http://localhost:9001/services/SimpleStockQuoteService/"/>  
                      </endpoint>  
                  </target>  
                  <target>  
                      <endpoint name="vendorC">  
                          <address uri="http://localhost:9002/services/SimpleStockQuoteService/"/>  
                      </endpoint>  
                  </target>  
              </clone>  
          </inSequence>  
          <outSequence>  
              <log level="full"/>  
              <aggregate>  
                  <completeCondition>  
                      <messageCount min="3"/>  
                  </completeCondition>  
                  <onComplete xmlns:m1="http://services.samples/xsd" xmlns:m0="http://services.samples" expression="//m0:return">  
                      <enrich>  
                          <source xmlns:m1="http://services.samples/xsd" clone="true" xpath="//m0:return[not(preceding-sibling::m0:return/m1:last &lt;= m1:last) and not(following-sibling::m0:return/m1:last &lt; m1:last)]"/>  
                          <target type="body"/>  
                      </enrich>  
                      <send/>  
                  </onComplete>  
              </aggregate>  
          </outSequence>  
      </target>  
  </proxy>  
</definitions>

Simulating the sample scenario

  1. Use a SOAP client like SoapUI to send the following request to the ScatterGatherProxy service.

    Code Block
    languagehtml/xml
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">  
       <soapenv:Header/>  
       <soapenv:Body>  
          <ser:getSimpleQuote>  
             <ser:symbol>foo</ser:symbol>  
          </ser:getSimpleQuote>  
       </soapenv:Body>  
    </soapenv:Envelope>  
  2. Because the log mediator is enabled inside the outSequence, there will be three responses from the three vendors. The logs will be similar to the following:

    Image Modified

  3. In SoapUI, you will get the response from the vendor providing the best quote as follows:

    Image Modified

  4. Compare the logged response messages with the response received by the client to see that the ScatterGatherProxy service returns the best quote to the client.

How the implementation works

...