繁体   English   中英

WSO2并行处理

[英]WSO2 parallel processing

我想复制一个请求并并行调用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>{ &#xd;
    "test" : "test"&#xd;
}</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>{&#xd;
"PROP_1" : "$1",&#xd;
"PROP_2" : "$2",&#xd;
"PROP_3" : "$3&#xd;
}</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"
}

您可以参考以下示例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]文章。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM