我想要复制一个请求并并行调用3个后端,然后将响应连接到一个响应中,并将其保留用于进一步的中介,我不知道如何做,甚至不知道它是否可能
我尝试过克隆中介器并将continueParent设置为true,但它并不等待克隆中的消息被处理,而只是跳过它。
在本例中,我只使用了自定义属性
<?xml version="1.0" encoding="UTF-8"?>
<api context="/test" name="test" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<payloadFactory description="test payload" media-type="json">
<format>{ 
"test" : "test"
}</format>
<args/>
</payloadFactory>
<clone continueParent="true" id="TEST_ID">
<target>
<sequence>
<log>
<property name="property_name" value="CLONE1"/>
</log>
<property name="PROP_1" scope="default"
type="STRING" value="1"/>
</sequence>
</target>
<target>
<sequence>
<log>
<property name="property_name" value="CLONE2"/>
</log>
<property name="PROP_2" scope="default" type="STRING" value="2"/>
</sequence>
</target>
<target>
<sequence>
<log>
<property name="property_name" value="CLONE3"/>
</log>
<property name="PROP_3" scope="default" type="STRING" value="3"/>
</sequence>
</target>
</clone>
<payloadFactory media-type="json">
<format>{
"PROP_1" : "$1",
"PROP_2" : "$2",
"PROP_3" : "$3
}</format>
<args>
<arg evaluator="xml" expression="$ctx:PROP_1"/>
<arg evaluator="xml" expression="$ctx:PROP_1"/>
<arg evaluator="xml" expression="$ctx:PROP_1"/>
</args>
</payloadFactory>
<log level="full"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>预期结果:
{
"PROP_1" : "1",
"PROP_2 : "2",
"PROP_3" : "3"
}发布于 2019-02-17 18:26:57
您可以参考以下示例api调用多个后端并聚合响应。
<api xmlns="http://ws.apache.org/ns/synapse" name="test" context="/test">
<resource methods="POST">
<inSequence>
<clone id="TEST_ID">
<target>
<sequence>
<log>
<property name="CLONE_01" value="BEFORE_CALL"/>
</log>
<call>
<endpoint>
<address uri="http://www.mocky.io/v2/5c692f27370000cc0707fcf4" format="get"/>
</endpoint>
</call>
<log level="full">
<property name="CLONE_01" value="AFTER_CALL"/>
</log>
<loopback/>
</sequence>
</target>
<target>
<sequence>
<log>
<property name="CLONE_02" value="BEFORE_CALL"/>
</log>
<call>
<endpoint>
<address uri="http://www.mocky.io/v2/5c692f35370000cc0a07fcf5" format="get"/>
</endpoint>
</call>
<log level="full">
<property name="CLONE_02" value="AFTER_CALL"/>
</log>
<loopback/>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<property name="info" scope="default">
<Information/>
</property>
<aggregate>
<completeCondition>
<messageCount min="2" max="-1"/>
</completeCondition>
<onComplete expression="$body/*[1]" enclosingElementProperty="info">
<send/>
</onComplete>
</aggregate>
</outSequence>
<faultSequence/>
</resource>
</api>这将是这个的输出。
{"Information":[{"EP":"01"},{"EP":"02"}]}您也可以参考这篇[1]文章。
https://stackoverflow.com/questions/54716799
复制相似问题