本文介绍了wso2 ESB:拆分/聚集模式-单个响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是 不是问题 ,而是 answer 。我对wso2 ESB还是很陌生,想进行一次测试,以实现将POE的拆分/收集EIP实施。
我按照发现的示例进行操作,并立即获得了可返回单个响应的有效配置。但是,要获得所有答复,需要花费大量时间才能弄清楚。大多数给定的样本似乎产生了相同的意外结果。我希望如果遇到同样的问题,这些行对您也会有所帮助。

This is not a question but rather an answer. I am quite new to wso2 ESB and wanted to make a test run implementing the split/gather EIP as part of a POC.I followed the examples I found and immediately got a working config that returned a single response. However to get all the responses back took quite some amount of time to figure out. Most given samples seemed to create the same unexpected result. I hope that if you run into the same kind of problem these lines will be helpfull to you.

我将 soapUI示例服务 (搜索操作)用作服务后端。我向代理服务器发送了一条搜索 两个项目 的组合消息(请参见下面的人工产品) 迭代中介者拆分 消息并将其转发到调用soapUI模型的端点。 聚合中介器 等待所有响应并将其放入一条结果消息中。

I used the soapUI sample service (search operation) as service backend. I sent a combined message searching for two items to the proxy server (see artefact below) The iterate mediator splits the message and forwards it to the endpoint that's calling the soapUI mockup. The aggregate mediator waits for all responses and tries to put it into one result message.

尽管拆分器运行正常,但聚合器仅返回 一个结果元素 ,而不是预期的元素列表。所有日志都显示一切正常,几个请求已发送到相应的端点,但最终响应中仍然只显示返回的第一个响应。

Although the splitter was working correctly, the aggregator returned only one result element not a list of elements as expected. All logs showed that everything was fine, several requests were sent to the corresponding endpoints but still only the first response that returned was visible in the final response.

在将代理的日志级别设置为TRACE之后,我意识到聚合器工作得很好,只是它创建了一条并非真正符合SOAP的消息。所有 聚合元素 都被添加到 直接在肥皂主体下方 。所以问题是如何在body和result标签之间添加一个根元素。我先尝试了XSLT,但它也只能读取正文的第一个子元素。最终,我找到了一些深层的暗示,以 使用 丰富的调解人 (或更确切地说是一系列),并且做到了。
以下列表说明了大多数示例中未发现的配置部分(如下所示)。

After setting the log level of the proxy to TRACE I realized that the aggregator worked just fine, only it created a message that wasn't really SOAP conform. All aggregated elements were added directly beneath the soap body. So the question was how to add one root element between body and result tags. I tried XSLT first but it also could read only the first child element of the body. Finally I found some deeply buried hint to use the enrich mediator (or rather a series of that) and that did the trick.The following list explains the part of the config (code shown below) that is not to be found in most examples.


  1. 使用第一个Enrich将所有相关项捕获到一个属性中

  2. 忘记当前消息-用仅包含新的有效负载根元素的主体重写完整的信封

  3. 将属性中存储的元素附加到新的有效负载根目录。

  4. 如果需要,将soap标头捕获到属性中并将其附加到新的味精中(不在

  1. Use first Enrich to capture all relevant items into a property
  2. Forget about the current message - rewrite the complete envelopewith the body containing only the new payload root element
  3. Attach the elements stored in the property to the new payload root.
  4. If required capture the soap header into a property and attach it into the new msg (not in the config below)



制品



演示请求



Artefacts

Demo Request

<body>
   <sam:multisearch xmlns:sam="http://www.example.org/sample/">
      <sam:search>
         <sessionid>123</sessionid>
         <searchstring>Item 1</searchstring>
      </sam:search>
      <sam:search>
         <sessionid>123</sessionid>
         <searchstring>Item 2</searchstring>
      </sam:search>
   </sam:multisearch>
</body>



Config



Config

<proxy xmlns="http://ws.apache.org/ns/synapse" name="test.multisearch" transports="https,http" statistics="enable" trace="enable" startOnLoad="true">
   <target>
      <inSequence>
         <iterate xmlns:sam="http://www.example.org/sample/" expression="//sam:multisearch/sam:search">
            <target>
               <sequence>
                  <send>
                     <endpoint key="soapUI_Mockup"/>
                  </send>
               </sequence>
            </target>
         </iterate>
      </inSequence>
      <outSequence>
         <aggregate>
            <completeCondition>
               <messageCount min="-1" max="-1"/>
            </completeCondition>
            <onComplete xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.example.org/sample/" expression="//sam:searchResponse">
               <enrich>
                  <source clone="true" xpath="$body//item"/>
                  <target type="property" property="ResultItems"/>
               </enrich>
               <log level="custom">
                  <property name="ResultItems" expression="get-property('ResultItems')"/>
               </log>
               <enrich>
                  <source type="inline" clone="true">
                     <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                        <soapenv:Header/>
                        <soapenv:Body>
                           <sam:GenericDataResponse/>
                        </soapenv:Body>
                     </soapenv:Envelope>
                  </source>
                  <target type="envelope"/>
               </enrich>
               <enrich>
                  <source type="property" clone="true" property="ResultItems"/>
                  <target action="child" xpath="//sam:GenericDataResponse"/>
               </enrich>
               <send/>
            </onComplete>
         </aggregate>
      </outSequence>
   </target>
   <description></description>
</proxy>



最后一个问题



如果有人可以提示我一些文档或为聚合介体的relatedeOn属性提供一些有效的配置,我将非常感谢。

Finally a question

If someone could hint me to some documentation or give me some working config for the correlateOn attribute of the aggregate mediator I'd really appreciate it.

推荐答案

聚合介体支持属性enclosingElementProperty,该属性用单个父元素包围响应。这简化了您的丰富技巧:

The aggregate mediator supports an attribute enclosingElementProperty which surrounds the responses with a single parent element. This simplifies your enrich trick:

<property name="ROOT" scope="default">
    <root:rootelement xmlns:root="www.wso2esb.com"/>
</property>
<aggregate>
    <completeCondition>
        <messageCount min="-1" max="-1"/>
    </completeCondition>
    <onComplete expression="//dummy" enclosingElementProperty="ROOT">
    </onComplete>
</aggregate>

这篇关于wso2 ESB:拆分/聚集模式-单个响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:05