I want to use Spring integration in my project, please help me with the pattern that I should go with as per my requirement

Viewed 84

I want to implement spring integration for my current requirement. The requirement is as follows -

  1. I have a service and I need to call 3 services parallelly from it.
  2. All the 3 calls are independent calls.
  3. Out of the 3 calls 2 calls are HTTP calls(1 GET, 1 POST) and another is a native method call.
  4. Once I make a POST call to my service then internally the three services should be called parallelly.
  5. The request body that I'm using to do the POST call should be used as an input for the other 3 calls but I need to change the input JSONs as per need. The exact input I'm not going to be using for the other 3 services but I'll be modifying the input as per my need.
  6. In the end once I get the response from the 3 mentioned services then I'll use a method to aggregate the JSONs and will use that Aggregated and transformed JSON as an input for another new service's input.

Kindly suggest me a correct pattern and with a little elaboration if possible as I'm totally new to Spring Integration.

1 Answers

So, to make a 3 parallel calls for the same payload and then aggregate their result, you need to look into a Scatter-Gather pattern: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#scatter-gather.

According to your description, you have to use a configuration based on the PublishSubscribeChannel (Auction) with a TaskExecutor provided. The subscribers to this channel could be plain HTTP message handler, service activator or even transformers to manipulate a payload before target service call.

Related