wso2 esb: Construct one message from multiple web service calls

醉酒当歌 提交于 2020-01-06 13:26:27

问题


I have a number of web services each returning a list of user ids as follows:

<application name="abc">
   <users>
     <id>123</id>
     <id>456</id>
     <id>789</id>
   </users>
</application>

I need to be able to

  1. Call a proxy service with a specific id (for example 123);
  2. Call each webservice and search for the ID;
  3. Create a response for each webservice and finally
  4. Aggregate all responses in one message which is sent to the client as follows:

<response>
  <id>123</id>
  <application name="abc">
      found
  </application>
  <application name="lmn">
      not found
  </application>
  <application name="xyz">
      found
  </application>
</response>

Its probably a mix of service chaining and aggregate, but I cannot figure out how to do it. I tried cloning a request and using send at the end with a receiving sequence which transforms the body using the payload factory. In the Out sequence I then used aggregate to combine the new messages. However it times out and I don't think it's a matter of timing. My main issue is how to create a new message from each webservice response the aggregate mediator can combine them.

Any help is appreciated.

Thanks


回答1:


You need to follow this pattern, https://docs.wso2.com/display/IntegrationPatterns/Scatter-Gather and you are almost there. When you define receive sequence the response will be forwareded to that sequence and you wouldn't get the response message in outSequence. Use aggregator mediator inside the outSequence and Combine the responses rather than defining a receive sequence.

Once you aggregate the responses, you can use xslt mediator to transform the message.




回答2:


I managed to solve my issue by creating a proxy service for each web servive. Each proxy service calls the actual web services and uses a filter in the out sequence to create a response likes this:

<application name="abc">
      found
  </application>

Then I created a REST API which takes the idno as a URI template. I then prepare a payload with this idno and clone the request to the proxy services I mentioned above. Then I aggregate the responses and add the idno in the payload.

If anybody has any questions let me know.



来源:https://stackoverflow.com/questions/24755003/wso2-esb-construct-one-message-from-multiple-web-service-calls

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