我在WSO2 Esb工作了几个月,我现在需要使用Iterator中介分割传入的消息,将每个部分发送到终点并使用聚合中介收集答案。 像这样:
<iterate expression="//element" id="ELEMENTS">
<target>
<sequence>
[send to endpoint using element data]
</sequence>
</target>
</iterate>
<property name="root" scope="default">
<root xmlns=""/>
</property>
<aggregate id="ELEMENTS">
<completeCondition timeout="12">
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="root" expression="//resultelement">
[rest of the flow]
</onComplete>
</aggregate>
它工作正常但是,正如您所看到的,我在聚合器上定义了超时,因此超时中的消息不会被聚合&#34;并将被重定向&#34;到故障序列。一般来说,发送到故障序列的任何消息都将会错过&#34;聚合器所以问题是:有没有办法在单个消息中聚合答案和错误?
&#34;计划B&#34;基于在故障序列中创建并使用响应中介发回的单个错误消息,它可以工作但是在多个错误的情况下我注意到esb的日志中的空指针异常,我假设由于多个进程试图使用回应调解员。
谢谢
修改:
我是ESB的新手,所以我可能有错误的想法,所以我试着通过一个例子解释我的案例。 我试图创建一个REST API来接收这样的有效负载:
{
"items" : [
"ID_ITEM_1",
"ID_ITEM_2",
"ID_ITEM_3"
]
}
API配置:
<?xml version="1.0" encoding="UTF-8"?>
<api context="AAA/report" name="order-request" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" protocol="http">
<inSequence>
<iterate expression="//items" id="ITEMS">
<target>
<sequence>
<property expression="json-eval($.items)" name="item"/>
<call-template description="Get status" target="gov:/calls/GetItemStatusTemplate.xml">
<with-param name="itemId" value="{get-property('item')}"/>
</call-template>
<payloadFactory media-type="json">
<format>
{
"item" : "$1",
"status" : "$2"
}
</format>
<args>
<arg expression="get-property('item')"/>
<arg evaluator="json" expression="$.status"/>
</args>
</payloadFactory>
</sequence>
</target>
</iterate>
<property name="report" scope="default">
<report xmlns=""/>
</property>
<aggregate id="ITEMS">
<completeCondition timeout="12">
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete enclosingElementProperty="report" expression="//jsonObject">
<respond/>
</onComplete>
</aggregate>
</inSequence>
<outSequence/>
<faultSequence>
<log level="full">
<property name="FAULT_SEQUENCE" value="IN"/>
</log>
<respond/>
</faultSequence>
</resource>
</api>
GetItemStatusTemplate将使用itemId来执行对端点的调用,如下所示:
<call>
<endpoint>
<address trace="disable" uri="http://something">
<timeout>
<duration>10000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</call>
让我们假设端点的答案如下:
{
"status" : "OK"
}
因此API对原始请求的回答(如果没有超时)应该是这样的:
{
"report" : [
{
"item" : "ID_ITEM_1",
"status" : "OK"
},
{
"item" : "ID_ITEM_2",
"status" : "NOT VALID"
},
{
"item" : "ID_ITEM_3",
"status" : "OK"
}
]
}
如果ITEM_3的请求超时,答案将是:
{
"report" : [
{
"item" : "ID_ITEM_1",
"status" : "OK"
},
{
"item" : "ID_ITEM_2",
"status" : "NOT VALID"
}
]
}
但我的想法是创造类似的东西:
{
"report" : [
{
"item" : "ID_ITEM_1",
"status" : "OK"
},
{
"item" : "ID_ITEM_2",
"status" : "NOT VALID"
},
{
"item" : "ID_ITEM_3",
"status" : "request timeout"
}
]
}
或者在ITEM_3上注意到客户端错误的方法
答案 0 :(得分:0)
在你的问题中,你要求在聚合调解员中处理“超时”。
会有以下警告:
WARN - Aggregate Aggregate Mediator Time out occured.
除此之外,不会重定向到故障序列。
在您的问题中,您要求汇总有错误的回复。如果可以,请详细解释您的问题。
注意:正如我在您的示例中看到的那样,您应该将聚合介体放入序列中,而不是添加到序列中。
希望这有助于得到你的答案。如果您需要更多说明,请对此问题发表评论。