[英]Conditional Routing based on JSON evaluation in WSO2
我有以下 JSON 數據:
{
"CustomerNames":{
"Update":[
{
"CustName":"Name1",
"id":"3"
},
{
"CustName":"Name3",
"id":"32"
}
],
"Create":[
{
"Name":"Name2"
}
]
}
}
如果存在 Update JSONARray,我需要調用 UpdateCustomer Sequence。 如果存在 Create JSONArray,我需要調用 CreateCustomer Sequence。 我正在嘗試使用 Conditional Router Mediator 來實現這一點。 我已嘗試使用以下代碼進行條件路由:
<property expression="json-eval($.CustomerNames.Update)" name="CREATE_PAYLOAD" scope="default" type="STRING"/>
<property expression="json-eval($.CustomerNames.Create)" name="UPDATE_PAYLOAD" scope="default" type="STRING"/>
<conditionalRouter continueAfter="true">
<conditionalRoute asynchronous="true" breakRoute="false">
<condition>
<match regex="true" source="boolean(get-property('CREATE_PAYLOAD'))"/>
</condition>
<target sequence="CREATE_CUSTOMER"/>
</conditionalRoute>
<conditionalRoute asynchronous="true" breakRoute="false">
<condition>
<match regex="true" source="boolean(get-property('UPDATE_PAYLOAD'))"/>
</condition>
<target sequence="UPDATE_CUSTOMER"/>
</conditionalRoute>
</conditionalRouter>
但這並沒有給出所需的 output。我在這里做錯了什么嗎?
Conditional Router Mediator
從 EI 6.5.0 開始移除,最新版本不支持。 因此,您可能需要使用Switch Mediator
來調用所需的序列。 在Switch Mediator中,如果找到匹配的case,就會執行,其余的switch case不做處理。 由於您需要調用兩個序列,因此可以使用兩個開關中介,如下所示,
<property expression="json-eval($.CustomerNames.Update)" name="CREATE_PAYLOAD" scope="default" type="STRING"/>
<property expression="json-eval($.CustomerNames.Create)" name="UPDATE_PAYLOAD" scope="default" type="STRING"/>
<switch source="boolean(get-property('CREATE_PAYLOAD'))">
<case regex="true">
<sequence key="CREATE_CUSTOMER"/>
</case>
<default/>
</switch>
<switch source="boolean(get-property('UPDATE_PAYLOAD'))">
<case regex="true">
<sequence key="UPDATE_CUSTOMER"/>
</case>
<default/>
</switch>
有關更多信息,請查看https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/switch-Mediator/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.