MilindaD
MilindaD

Reputation: 7653

Spring integration asynchronous communication synchronous response

I currently have an inbound https gateway. In the internal processing of the request from http gateway I call multiple http web services. Currently as I monitored from a debug point if I am calling 4 web services from a publish-subscribe channel they are executed one after another. Then after 4 of the services are called one by one they are aggregated and a response is returned. The problem here is that there is the potential to be N number of calls, so essentially there could only be 2 http web service calls or there could be even 100. In order to solve this I added a task executor to the publish subsce channel as follows

<int:publish-subscribe-channel id="ta-htl-data-router-channel" apply-sequence="true" task-executor="pool" />

<task:executor id="pool" pool-size="10"/>

Then while the web router channel subscribers are executed synchronously the http inbound gateway stops working properly, that is I get the following error message

Reply message received but the receiving thread has already received a reply

And I get a response json string TO DOWNLOAD instead of it being showed in the browser as a respone.

How I can I call multiple external web services asynchronously and send an aggregated response to the http inbound gateway. Therefore while the overall http inbound gateway request to response occurs synchronously the calling of the multiple external web services internally happens asynchronously to reduce the processing time.

Upvotes: 0

Views: 1344

Answers (2)

Gary Russell
Gary Russell

Reputation: 174504

You need to add an <aggregator/> to combine the results into a list, and some transformer aftrer that to construct the response from the results; the original http thread will be waiting for the result, according to the reply-timeout.

Upvotes: 0

Artem Bilan
Artem Bilan

Reputation: 121177

Consider using rejection-policy="CALLER_RUNS" on your <task:executor>.

The issue is may be in those long-running call for the web services, hance if you have more than 10 concurrent tasks, all others will be ABROTED by default.

Upvotes: 1

Related Questions