在WSO2 EI中进行迭代的最佳方法是什么?

问题描述 投票:1回答:2

阅读了《 WSO2 EI参考》之后,我仍然对如何在EI序列中使用迭代器感到困惑。就我而言,我有一个这样的有效载荷。...

   {
...
   "array": [
    {"cpf": "12345678911"},
    {"cnpj":"12345678912346"}
   ]
}

因此,我必须使用其他Web服务来检查这些家伙是否存在。为了实现该流程,我正在使用迭代介体来拆分消息,然后构建逻辑以进行如下验证。

enter image description here

实现此图像的代码如下:

 <iterate description="" expression="//jsonObject/array" id="myid">
                        <target>
                            <sequence>
                                <property expression="json-eval($.array.cpf)" name="tipoCPF" scope="default" type="STRING"/>
                                <filter description="" xpath="boolean(get-property('tipoCPF'))">
                                    <then>
                                        <property expression="json-eval($.array.cpf)" name="uri.var.cpf" scope="default" type="STRING"/>

                                        <call>
                                            <endpoint>
                                                <http method="get" uri-template="http://endpoint/service/{uri.var.cpf}"/>
                                            </endpoint>
                                        </call>
                                        <filter regex="200" source="get-property('axis2','HTTP_SC')">
                                            <then/>
                                            <else>
                                                <payloadFactory description="" media-type="json">
                                                    <format>{&#xd;
"code":"400",&#xd;
"error":"CPF inexistente"&#xd;
}</format>
                                                    <args/>
                                                </payloadFactory>
                                                <property name="HTTP_SC" scope="axis2" type="STRING" value="400"/>
                                                <respond/>
                                            </else>
                                        </filter>
                                    </then>
                                    <else>
                                        <property expression="json-eval($.array.cnpj)" name="tipoCNPJ" scope="default" type="STRING"/>
                                        <filter xpath="boolean(get-property('tipoCNPJ'))">
                                            <then>
                                                <property expression="json-eval($.array.cnpj)" name="uri.var.cnpj" scope="default" type="STRING"/>
                                                <header name="Authorization" scope="transport" value="Basic Y29yZS5jb25zdWx0aW5nOm8xNXRyZWI="/>
                                                <call>
                                                    <endpoint>
                                                        <http method="get" uri-template="http://endpoint/service/cnpj/{uri.var.cnpj}"/>
                                                    </endpoint>
                                                </call>
                                                <filter regex="200" source="get-property('axis2','HTTP_SC')">
                                                    <then/>
                                                    <else>
                                                        <payloadFactory media-type="json">
                                                            <format>{&#xd;
        "code":"400",&#xd;
        "error":"CNPJ inexistente"&#xd;
        }</format>
                                                            <args/>
                                                        </payloadFactory>
                                                        <property name="HTTP_SC" scope="axis2" type="STRING" value="400"/>
                                                        <respond/>
                                                    </else>
                                                </filter>
                                            </then>
                                            <else>
                                                <call>
                                                    <endpoint>
                                                        <http method="get" uri-template="http://endpoint/service/info"/>
                                                    </endpoint>
                                                </call>
                                            </else>
                                        </filter>
                                    </else>
                                </filter>
                            </sequence>
                        </target>
                    </iterate>

此迭代器作为'不顺序'内部的一部分工作。设计“无序”是为了允许在数据库中插入新的合同信息。问题:

添加此迭代器后,该服务开始在数据库中进行重复的插入。看起来迭代未在标签“迭代器”的边缘完成。就像迭代一直持续到其余的序列。Try:为了解决此问题,我尝试在迭代器之后添加一个聚合器介体。但是结束重复的插入是否持久还是无效,或者我收到错误消息。

那么在WSO2 EI中进行此迭代的正确乳清是什么?

阅读《 WSO2 EI参考》之后,我仍然对如何在EI序列中使用迭代器感到困惑。就我而言,我有一个这样的有效负载。...{...“ array”:[{“ cpf”:“ 12345678911”},...

wso2 wso2ei mediator ei
2个回答
0
投票

正如您已经提到的,即使在使用聚合介体之前,迭代也将在迭代标记之外进行。要解决此问题,您需要添加聚合介体inside


0
投票

感谢您对阿鲁南的帮助!在您回答之后,我尝试如下添加聚合器Adding the Aggregator Mediator

© www.soinside.com 2019 - 2024. All rights reserved.