0

In case of scatter gather static channels are defined(i.e channels are known prior designing ) from which the response will be aggregated .

Is it possible to call the same api multiple times based on the size of array list(dynamic list).

In my case ,have java arraylist(dynamic) of size 3(size differs each time) like

ArrayList
    1-> request for business api call(samp)
    2-> request for business api call(samp)
    3-> request for business api call(samp)   

i.e for each element of arraylist i need to call the business api(samp is the business api, here it should be called 3 times). Since size differs each time , how to apply scather gather spring integration pattern here? Is any other spring integration pattern can be applied here?

Things done for above problem (but below approach is a Sequential way of handling ,is it possible to process each call parallely) :

Arraylist apiResponse
for each element in array list  
    call business api 
    apiResponse.add(eachElement Response)

spring integration , java , enterprise integration pattern

  • Would you mind to explain and show what are those dynamic channel and they are configured in you application and who are consumers of them. I'm asking because there is no such a notation `dynamic channel` in Spring Integration and we have to know your use-case first of all to be able to help you somehow – Artem Bilan Apr 04 '17 at 11:53
  • Thanks for the reply. i need to call the business api multiple times. The number of times is known only based on the size of arraylist @ runtime. I have edited dynamic channel with appropriate sentence. – Sandeep Reddy Apr 04 '17 at 13:09

1 Answers1

0

I would like to have more information about your use-case. Maybe you can explain it from the business requirements perspective.

Anyway, based on provided info like:

i need to call the business api multiple times

I can suggest the solution like Splitter:

@Splitter(inputChannel = "input", outputChannel = "output")
public List<String> split(String payload, @Header int size) {
    return Stream.generate(() -> payload)
            .limit(size)
            .collect(Collectors.toList());
}

So, in this case you generate a list of the same object with size from headers.

The output channel can be an ExecutorChannel to let process data (call business API) in parallel. After that call you should use an aggregator to gather results.

According to your description the Scatter-Gather doesn't fit your requirements.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118