Reputation: 23
I am beginner in spring integration api development.
API requirements are as below, I need to design and develop a http rest api(POST) which accepts some request body and which internally calls 2 external apis and based on those api responses, provide a response payload to end user.
About 2 external apis, First flow, if first of the 2 external apis give exception, provide that(or wrap it in a nice response) to end user. and if first api returns 200 OK then proceed on calling second external api, fetch its result, do some validation checks and return appropriate http response(might contain exceptions or 200 OK)
Can you please help with what all spring components I can use?
for the main api, I am thinking of using int-http:inbound-gateway, then form request payload using request-payload-type on int-http:inbound-gateway, service activator to form a message using given http headers and given payload and send it to output channel.
this is where confusion begins, should I use pub sub channel and call first external api and send its result to final output channel in case of exceptions and to the other middle output channel in case of 200 Ok, if yes how can I do that? and then use that middle output channel to fetch result and call second external api and send results to final/other output channel depending on the response I get from second external api.
we are using xml's for development.
Your help is really appreciated.
Upvotes: 0
Views: 110
Reputation: 121552
Consider to investigate a Scatter-Gather: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#scatter-gather.
Depending on the PublishSubscribeChannel
configuration (ignoreFailures
and executor
), you may see a request to the second service or not. I would say its default behavior is what you are asking for. You probably would need to have some error handling in case of exception from the first service, but see in a docs what could be possible with that Scatter-Gather.
Upvotes: 0