【问题标题】:WSO2 EI send objects responded from an endpoint to another endpoint one by oneWSO2 EI发送对象从一个端点一一响应到另一个端点
【发布时间】:2021-06-06 04:06:59
【问题描述】:

我是 WSO2 EI 的新手,正在尝试从端点获取数据并将响应对象的每个对象发送到另一个端点。对于下一步,如果可以完成,我想向用户显示一个进度条,以了解流程是如何进行的。

在通过 github 和 stackoverflow 阅读和搜索 WSO2 文档和示例后,找不到任何完整的示例来展示如何完全执行此过程。

作为我使用 Integration Studio 完成的工作示例,这是一个 API,它调用端点从 server1 获取数据,然后调用第二个端点将响应的数据发送到 server2,它工作正常。

<?xml version="1.0" encoding="UTF-8"?>
<api context="/Product/UpdatePrice" name="ProductUpdatePrice" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" url-mapping="/All">
        <inSequence>
            <call>
                <endpoint name="HTTPEndpoint">
                    <http method="get" uri-template="https://server1/api/Goods/GetPrices">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>1</progressionFactor>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <log level="custom">
                <property expression="json-eval($.message)" name="test"/>
            </log>
            <script language="nashornJs"><![CDATA[payload = mc.getPayloadJSON();
                var res = payload.response;
                mc.setPayloadJSON(res);]]></script>
            <call>
                <endpoint name="HTTPEndpoint">
                    <http method="post" uri-template="https://server2/api/Product/UpdateAllPrices">
                        <suspendOnFailure>
                            <initialDuration>-1</initialDuration>
                            <progressionFactor>1</progressionFactor>
                        </suspendOnFailure>
                        <markForSuspension>
                            <retriesBeforeSuspension>0</retriesBeforeSuspension>
                        </markForSuspension>
                    </http>
                </endpoint>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>

在此示例中,从 server1 响应的产品价格将发送到 server2 以更新那里的数据库。

我想要的是使用迭代调用 server2 API 来一个一个发送 server1 响应的对象。

正如我在搜索中发现的那样,似乎我必须使用如下迭代,但不知道在我的示例中我必须在哪里使用它。

    <iterate attachPath="json-eval($.categories)" expression="json-eval($.categories)" id="iterate-over-cats" preservePayload="true">
        <target>
            <sequence>
                <send>
                    <endpoint>
                        <http method="post" uri-template="https://server2/api/Product/UpdatePrice">
                            <suspendOnFailure>
                                <initialDuration>-1</initialDuration>
                                <progressionFactor>1</progressionFactor>
                            </suspendOnFailure>
                            <markForSuspension>
                                <retriesBeforeSuspension>0</retriesBeforeSuspension>
                            </markForSuspension>
                        </http>
                    </endpoint>
                </send>
            </sequence>
        </target>
    </iterate>

任何想法都会受到赞赏。

【问题讨论】:

    标签: xml api wso2 esb ei


    【解决方案1】:

    假设 Server1 返回一个对象列表,您的解决方案已经使用建议的迭代器完成,您可以将它放在您当前在示例中调用的位置。根据您是否希望流程在迭代后继续,您必须在其之后添加聚合中介。 [1] 我用调用替换了发送,否则迭代器响应将在 outSequence 中结束。

    <?xml version="1.0" encoding="UTF-8"?>
    <api context="/Product/UpdatePrice" name="ProductUpdatePrice" xmlns="http://ws.apache.org/ns/synapse">
        <resource methods="GET" url-mapping="/All">
            <inSequence>
                <call>
                    <endpoint name="HTTPEndpoint">
                        <http method="get" uri-template="https://server1/api/Goods/GetPrices">
                            <suspendOnFailure>
                                <initialDuration>-1</initialDuration>
                                <progressionFactor>1</progressionFactor>
                            </suspendOnFailure>
                            <markForSuspension>
                                <retriesBeforeSuspension>0</retriesBeforeSuspension>
                            </markForSuspension>
                        </http>
                    </endpoint>
                </call>
                <log level="custom">
                    <property expression="json-eval($.message)" name="test"/>
                </log>
                <script language="nashornJs"><![CDATA[payload = mc.getPayloadJSON();
                    var res = payload.response;
                    mc.setPayloadJSON(res);]]></script>
           <iterate attachPath="json-eval($.categories)" expression="json-eval($.categories)" id="iterate-over-cats" preservePayload="true">
            <target>
                <sequence>
                    <call>
                        <endpoint>
                            <http method="post" uri-template="https://server2/api/Product/UpdatePrice">
                                <suspendOnFailure>
                                    <initialDuration>-1</initialDuration>
                                    <progressionFactor>1</progressionFactor>
                                </suspendOnFailure>
                                <markForSuspension>
                                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                                </markForSuspension>
                            </http>
                        </endpoint>
                    </call>
                </sequence>
            </target>
        </iterate>
    <!-- Basic aggregate here to correctly exit the iterate mediator --> 
                <respond/>
            </inSequence>
            <outSequence/>
            <faultSequence/>
        </resource>
    </api>
    
    

    [1]https://docs.wso2.com/display/EI660/Iterate+Mediator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-14
      • 2020-07-30
      • 2021-07-15
      • 2015-11-06
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      相关资源
      最近更新 更多