Sequential back-end calls in WSO2 EI/ESB

你离开我真会死。 提交于 2020-05-15 21:48:07

问题


In my case, the response from the first back-end call is in Array of Objects format as below:

Response:

"Entity": {
        "related-List": [
            {
                "fname": "abc",
                "lname": "xyz",
                "bdate": "2013-01-25",
                "accType": "Cur",
                "accNum": "54736",
                "bal": 901,
                "address": "USA"
            },
            {
                "fname": "def",
                "lname": "pqr",
                "bdate": "2013-01-25",
                "accType": "Sav",
                "accNum": "12345",
                "bal": 901,
                "address": "USA"
            },
            {
                "fname": "ghi",
                "lname": "stu",
                "bdate": "2013-01-25",
                "accType": "Dep",
                "accNum": "87654",
                "bal": 901,
                "address": "USA"
            }
]
}

*************/

So in the second call, I want to use the "accType" and "accNum" from the response and make the back-end call for the number of objects present in the response array. For this, I need to use Iterate or ForEach like:

<foreach>
<call>
            <endpoint>
               <http method="POST" uri-template="http://localhost:6754/v2/{accType}/{accNum}"/>
            </endpoint>
</call>
</foreach>

OR

<iterate>
    <call>
                <endpoint>
                   <http method="POST" uri-template="http://localhost:6754/v2/{accType}/{accNum}"/>
                </endpoint>
    </call>
</iterate>

What is the correct way to implement it?


回答1:


You cannot use Send or Call mediators inside Foreach mediator. Hence you have to use Iterate mediator. You can use Iterate mediator expression as json-eval($. Entity.related-List) and iterate through the array.



来源:https://stackoverflow.com/questions/61653131/sequential-back-end-calls-in-wso2-ei-esb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!