我正在尝试使用clone调用两个端点并收集他们的信息以使用聚合发送,我必须将它与scatter-gather中介一起使用。每个端点都在json中返回一个字符串。但我一直在“期待SOAP Envelope的实现作为父”错误。我的最后一次尝试如下。我应该在onComplete表达式中使用什么来使其工作?
<resource methods="GET" uri-template="/allInfo">
<inSequence>
<log description="Get All Restaurants Info" level="custom" separator=",">
<property name="message" value=""All information of restaurants""/>
</log>
<clone description="All Info" id="ScatterGatherProxy">
<target>
<endpoint key="RestaurantLocalsEP"/>
</target>
<target>
<endpoint key="RestaurantNamesEP"/>
</target>
</clone>
</inSequence>
<outSequence>
<aggregate id="ScatterGatherProxy">
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="fn:concat('//*')">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</resource>
聚合中介包含来自最新版本(6.5.0)的本机JSON支持(即将发布)此外,通过WUM更新可为EI 6.1.1和6.4.0提供JSON支持。
您可以使用以下示例配置
<api xmlns="http://ws.apache.org/ns/synapse" name="aggregate"
context="/testAgg"> <resource methods="POST GET">
<inSequence>
<log level="custom" separator=",">
<property name="message" value=""All information of restaurants""/>
</log>
<clone id="ScatterGatherProxy">
<target>
<endpoint name="Cape">
<address uri="http://www.mocky.io/v2/5befbf782f000067007a0be4" format="get"/>
</endpoint>
</target>
<target>
<endpoint name="KSC">
<address uri="http://www.mocky.io/v2/5befbfd22f00009a007a0be5" format="get"/>
</endpoint>
</target>
</clone>
</inSequence>
<outSequence>
<aggregate id="ScatterGatherProxy">
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="json-eval($)">
<send/>
</onComplete>
</aggregate>
</outSequence> </resource> </api>
您可以在https://lahirumadushankablog.wordpress.com/2018/11/17/aggregating-json-payloads-in-wso2-ei/中阅读更多信息
您需要添加一个enclosingElementProperty标记,以便在完成条件下将所有输出收集到一个中。
例如,您可以尝试以下操作
<property name="Aggregated_Responses" scope="default">
<jsonObject/>
</property>
<aggregate id="NIRO">
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="$body/*[1]"
enclosingElementProperty="Aggregated_Responses">
<send/>
</onComplete>
</aggregate>
谢谢