0

It's about using one API's reply channel in another API.

I have API 1 which does some operations on the entity and unlocks the entity. & API 2 which unlocks an entity. I have make them work so that they can be called independently.

API2 unlocks the entity using http inbound and outbound gateway.

I am calling API2's http inbound gateway request-channel in API1 to call API2(to implement unlock part of API1) and if API2 returns success, I want to send custom success response from API1 so for that purpose, I am using API2's reply channel as a input channel in API1 which is messing things up.

so If I call API2 independently, at the end it also calls API1 chain flow where API2's reply channel is used as input channel(which is obvious) and throwing exception Expression evaluation failed as I am using some variable from the chain above.

Is there any way to handle it in a better way? Please help!

1 Answers1

0

Doesn't look like your design is OK. Since you have some common API to be called from API1 and API2, then just extract it into that separate internal API. For that purpose you indeed can use some input channel for a service activator call.

Your API1 and API2 must not use any reply channel, but reply on just replyChannel header populated by the request-reply pattern implementation in the inbound gateway. You are making a mess exactly with that reply-channel on those inbound gateways.

We don't know what is your configuration, so cannot give you more precise advice. But one more time: the inbound gateway populates a replyChannel header and the last endpoint in the downstream flow simply can reply on this header to produce a reply into a proper place.

I think we already had with your similar discussion over here: calling http rest API from another API.

Either way, please, learn what is replyChannel header and try to avoid using those reply-channel configurations, especially if you are going to reuse downstream sub-flow from different places: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway

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