Mike Cornell
Mike Cornell

Reputation: 6059

Making Async calls to HTTP Outbound Gateway

I have a system that I am looking at retrofitting a backend with spring integration.

A few of the patterns in this system, look at hitting the same web service and/or HTTP server (I have both) with multiple requests and slightly different parameters. The results are then aggregated together and presented to the user

I have it working successfully in a synchronous mode, where the request comes in thru a Gateway, is "split" into messages that contain the key value for each call (call with A, call with B, call with XYZ). Each message then goes to an HTTP Outbound Gateway, the call is made, and is returned. The results are then aggregated together and shipped back through the Gateway.

What I'm struggling with is making these HTTP calls asynchronously. The current system uses Futures to make each call in a separate thread. I would like a similar pattern.

What I think I need to do is to create a second Gateway, which wraps the HTTP outbound gateway, and use the return value to create an async call. However, I'm not sure how this would work with the aggregation, and something about it feels like there should be a cleaner way. I haven't had the opportunity to use Spring Integration in 3 years, so I'm trying to relearn all the things.

Am I missing something, or is this how you need to do it?

Upvotes: 3

Views: 2214

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

You can simply make the channels (to which the outbound-gateways are subscribed) ExecutorChannels ( http://static.springsource.org/spring-integration/reference/html/messaging-channels-section.html#executor-channel and http://static.springsource.org/spring-integration/reference/html/messaging-channels-section.html#channel-configuration-executorchannel).

That way, each request will run on a separate thread - the aggregation release will occur on the thread that receives the final response. Your original thread will wait in the gateway for the response (or you can use an async gateway and wait on a Future.

Upvotes: 3

Related Questions