WSO2 ESB : Aggregate node droppping message after

2019-08-29 06:01发布

问题:

I am implementing the Fan out -- Fan in splitter EIP inside a proxy , whereby :

                |-----> shoe store-(1-M)-------------
productSearchRq --                                     |-->Rs
                |-----> ack clothes store-(0-1)------

Shoe store = Data service and Clothes store = Axis 2 service .

So in short I implement the pattern above ; I clone the request , send it , get responses , format them using payloadFactory:

<productDetails>
   <productID>$1</productID>
   <productName>$2</productName>
   <productSize>$3</productSize>
   <productColour>$4</productColour>
   <productType>$5</productType>
   <sourceID>$6</sourceID>
</productDetails>

on both responses ( and iterate [//productDetails , iterate id = iT] on shoe products since it's one to many). Then in the following response handler , I try to aggregate all these productDetails.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="productSearchHandler">
   <log level="custom">
      <property name="pocSearchRsHandlerSeq reached" value="++++++++++++++=========Aggregating now========+++++++++++++++++=="></property>
   </log>
   <aggregate id="iT">
      <completeCondition>
         <messageCount min="-1" max="-1"></messageCount>
      </completeCondition>
      <onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="//productDetails">
         <log level="custom" separator=",">
            <property name="::::" value="======================= Formatting the Aggregated Responses. ==============="></property>
         </log>
         <log level="full"></log>
      </onComplete>
   </aggregate>
   <aggregate>
      <completeCondition>
         <messageCount min="-1" max="-1"></messageCount>
      </completeCondition>
      <onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="//productDetails">
         <payloadFactory media-type="xml">
            <format>
               <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prod="http://za.co.pepkor/product_service/">
                  <soapenv:Body>
                     <prod:productSearchResp> $1                                                                                                </prod:productSearchResp>
                  </soapenv:Body>
               </soapenv:Envelope>
            </format>
            <args>
               <arg expression="//productDetails" evaluator="xml"></arg>
            </args>
         </payloadFactory>
         <switch source="get-property('CallType')">
            <case regex="SOAP">
               <send></send>
            </case>
            <case regex="REST">
               <property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
               <send></send>
            </case>
            <default></default>
         </switch>
      </onComplete>
   </aggregate>
</sequence>

The filter's there to cater for the API implementation of this proxy. And I do need 2 aggregators because I use a clone AND iterator mediator.

So I am wondering why before my second aggregator , the message is being "reset" to an empty soap message and therefore the 2nd agg fails to find //productDetails. See following log entries :

After 1st agg which aggregates shoe prods:

TID: [0] [ESB] [2015-02-27 09:46:24,520] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merging message : <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><productID>1124596</productID><productName>REEBOK_SNEAKERS</productName><productSize>7</productSize><productColour>BROWN</productColour><productType>SHOES</productType><sourceID>SHC</sourceID></productDetails></soapenv:Body></soapenv:Envelope> using XPath : //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
TID: [0] [ESB] [2015-02-27 09:46:24,522] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merged result : <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><productID>1452168</productID><productName>PUMPS</productName><productSize>7</productSize><productColour>ORANGE</productColour><productType>SHOE</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1124596</productID><productName>REEBOK_SNEAKERS</productName><productSize>7</productSize><productColour>BROWN</productColour><productType>SHOES</productType><sourceID>SHC</sourceID></productDetails></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
TID: [0] [ESB] [2015-02-27 09:46:24,523] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merging message : <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><productID>1123456</productID><productName>NIKE_SHIRTS</productName><productSize>7</productSize><productColour>RED</productColour><productType>SHIRT</productType><sourceID>SHC</sourceID></productDetails></soapenv:Body></soapenv:Envelope> using XPath : //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
TID: [0] [ESB] [2015-02-27 09:46:24,525] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merged result : <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><productID>1452168</productID><productName>PUMPS</productName><productSize>7</productSize><productColour>ORANGE</productColour><productType>SHOE</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1124596</productID><productName>REEBOK_SNEAKERS</productName><productSize>7</productSize><productColour>BROWN</productColour><productType>SHOES</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1123456</productID><productName>NIKE_SHIRTS</productName><productSize>7</productSize><productColour>RED</productColour><productType>SHIRT</productType><sourceID>SHC</sourceID></productDetails></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}

Then as we are going into 2nd agg :

TID: [0] [ESB] [2015-02-27 09:46:24,545] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Generating Aggregated message from : <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><noItemFound>No item in Ackerman's</noItemFound></productDetails></soapenv:Body></soapenv:Envelope> {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
TID: [0] [ESB] [2015-02-27 09:46:24,547] DEBUG {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Merging message : <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body></soapenv:Body></soapenv:Envelope> using XPath : //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}
TID: [0] [ESB] [2015-02-27 09:46:24,550] ERROR {org.apache.synapse.mediators.eip.aggregator.AggregateMediator} -  Error evaluating expression: //productDetails {org.apache.synapse.mediators.eip.aggregator.AggregateMediator}

What I want is to merge

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><productID>1452168</productID><productName>PUMPS</productName><productSize>7</productSize><productColour>ORANGE</productColour><productType>SHOE</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1124596</productID><productName>REEBOK_SNEAKERS</productName><productSize>7</productSize><productColour>BROWN</productColour><productType>SHOES</productType><sourceID>SHC</sourceID></productDetails><productDetails><productID>1123456</productID><productName>NIKE_SHIRTS</productName><productSize>7</productSize><productColour>RED</productColour><productType>SHIRT</productType><sourceID>SHC</sourceID></productDetails></soapenv:Body></soapenv:Envelope>

with

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><productDetails><noItemFound>No item in Ackerman's</noItemFound></productDetails></soapenv:Body></soapenv:Envelope>

回答1:

Hi if you are using clone mediator with one aggregate mediator you can aggregate the response from two different services. check this tutorial how that works

http://architects.dzone.com/articles/wso2-esb-cloning-and