使用 WSO2 聚合器组合多个 JSON 数组
Combining multiple JSON arrays using WSO2 aggregator
我正在尝试使用 WSO2 ESB 将两个不同的数据源合并到一个数据源中。因为不同的源具有不同的数据格式,所以我的方法是为每个端点创建一个代理来处理授权和有效负载格式,以便 return 和 JSON 数组。根据研究,我的假设是我可以使用聚合器 medior 来组合结果。在完成大量示例后,我成功地将两个数组组合在一起,但是其中一个数组总是重复的。谁能看出我做错了什么,或者有人对实现两个 JSON 数组组合的更好方法有任何其他建议吗?
我设置了以下代码示例来模拟 2 个提要,然后与我的代码结合使用:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testb_url1" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<payloadFactory media-type="json">
<format>[
{"id": "1",
"type": "object",
"name": "first"},
{"id": "2",
"type": "object",
"name": "second"}
]
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
URL数2
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testb_url2" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<payloadFactory media-type="json">
<format>[
{"id": "10",
"type": "object",
"name": "ten"},
{"id": "11",
"type": "object",
"name": "eleven"}
]
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
合并代码:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testb_combine" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property name="enclosing_element" scope="default">
<jsonArray xmlns=""/>
</property>
<send>
<endpoint>
<recipientlist>
<endpoint>
<address uri="http://localhost:8280/services/testb_url1/" trace="disable"/>
</endpoint>
<endpoint>
<address uri="http://localhost:8280/services/testb_url2/" trace="disable"/>
</endpoint>
</recipientlist>
</endpoint>
</send>
</inSequence>
<outSequence>
<enrich>
<source clone="true" xpath="$body/jsonArray/jsonElement"/>
<target action="child" xpath="$ctx:enclosing_element"/>
</enrich>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="$body/jsonArray/jsonElement"
enclosingElementProperty="enclosing_element">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</target>
</proxy>
和 returned 结果显示来自 URL 1 个重复的数据:
[
{
"id": 1,
"type": "object",
"name": "first"
},
{
"id": 2,
"type": "object",
"name": "second"
},
{
"id": 1,
"type": "object",
"name": "first"
},
{
"id": 2,
"type": "object",
"name": "second"
},
{
"id": 10,
"type": "object",
"name": "ten"
},
{
"id": 11,
"type": "object",
"name": "eleven"
}
]
删除后序中的丰富介体,它会像你想要的那样工作:
代理服务:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testb_combine"
transports="https http"
startOnLoad="true">
<target>
<inSequence>
<property name="enclosing_element" scope="default">
<jsonArray xmlns=""/>
</property>
<send>
<endpoint>
<recipientlist>
<endpoint>
<address uri="http://localhost:8283/services/testb_url1/"/>
</endpoint>
<endpoint>
<address uri="http://localhost:8283/services/testb_url2/"/>
</endpoint>
</recipientlist>
</endpoint>
</send>
</inSequence>
<outSequence>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="$body/jsonArray/jsonElement"
enclosingElementProperty="enclosing_element">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</target>
</proxy>
回复:
[
{
"id": 1,
"type": "object",
"name": "first"
},
{
"id": 2,
"type": "object",
"name": "second"
},
{
"id": 10,
"type": "object",
"name": "ten"
},
{
"id": 11,
"type": "object",
"name": "eleven"
}
]
我正在尝试使用 WSO2 ESB 将两个不同的数据源合并到一个数据源中。因为不同的源具有不同的数据格式,所以我的方法是为每个端点创建一个代理来处理授权和有效负载格式,以便 return 和 JSON 数组。根据研究,我的假设是我可以使用聚合器 medior 来组合结果。在完成大量示例后,我成功地将两个数组组合在一起,但是其中一个数组总是重复的。谁能看出我做错了什么,或者有人对实现两个 JSON 数组组合的更好方法有任何其他建议吗?
我设置了以下代码示例来模拟 2 个提要,然后与我的代码结合使用:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testb_url1" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<payloadFactory media-type="json">
<format>[
{"id": "1",
"type": "object",
"name": "first"},
{"id": "2",
"type": "object",
"name": "second"}
]
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
URL数2
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testb_url2" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<payloadFactory media-type="json">
<format>[
{"id": "10",
"type": "object",
"name": "ten"},
{"id": "11",
"type": "object",
"name": "eleven"}
]
</format>
<args/>
</payloadFactory>
<log level="full"/>
<loopback/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</target>
</proxy>
合并代码:
<?xml version="1.0" encoding="UTF-8"?>
<proxy name="testb_combine" startOnLoad="true" trace="disable"
transports="https http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property name="enclosing_element" scope="default">
<jsonArray xmlns=""/>
</property>
<send>
<endpoint>
<recipientlist>
<endpoint>
<address uri="http://localhost:8280/services/testb_url1/" trace="disable"/>
</endpoint>
<endpoint>
<address uri="http://localhost:8280/services/testb_url2/" trace="disable"/>
</endpoint>
</recipientlist>
</endpoint>
</send>
</inSequence>
<outSequence>
<enrich>
<source clone="true" xpath="$body/jsonArray/jsonElement"/>
<target action="child" xpath="$ctx:enclosing_element"/>
</enrich>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="$body/jsonArray/jsonElement"
enclosingElementProperty="enclosing_element">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</target>
</proxy>
和 returned 结果显示来自 URL 1 个重复的数据:
[
{
"id": 1,
"type": "object",
"name": "first"
},
{
"id": 2,
"type": "object",
"name": "second"
},
{
"id": 1,
"type": "object",
"name": "first"
},
{
"id": 2,
"type": "object",
"name": "second"
},
{
"id": 10,
"type": "object",
"name": "ten"
},
{
"id": 11,
"type": "object",
"name": "eleven"
}
]
删除后序中的丰富介体,它会像你想要的那样工作: 代理服务:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testb_combine"
transports="https http"
startOnLoad="true">
<target>
<inSequence>
<property name="enclosing_element" scope="default">
<jsonArray xmlns=""/>
</property>
<send>
<endpoint>
<recipientlist>
<endpoint>
<address uri="http://localhost:8283/services/testb_url1/"/>
</endpoint>
<endpoint>
<address uri="http://localhost:8283/services/testb_url2/"/>
</endpoint>
</recipientlist>
</endpoint>
</send>
</inSequence>
<outSequence>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="$body/jsonArray/jsonElement"
enclosingElementProperty="enclosing_element">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</target>
</proxy>
回复:
[
{
"id": 1,
"type": "object",
"name": "first"
},
{
"id": 2,
"type": "object",
"name": "second"
},
{
"id": 10,
"type": "object",
"name": "ten"
},
{
"id": 11,
"type": "object",
"name": "eleven"
}
]