繁体   English   中英

WSO2 EI 发送对象从一个端点一一响应到另一个端点

[英]WSO2 EI send objects responded from an endpoint to another endpoint one by one

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

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

作为我使用 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>

任何想法将不胜感激。

假设 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

暂无
暂无

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

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