0

I have API 1 which is defined by int-http:inbound-gateway and has service activator to perform some business logic and sends output on output channel same as reply channel of the inbound gateway(simple flow)

I also have API 2 which is defined in different xml file which also has int-http:inbound-gateway and int-http:outbound-gateway which performs on its own.

Now I want to call API 2 from API 1 but I don’t want to send message of the output channel of first API 1 to API 2, API 1 output channel response if for the end user to consume! If I use request channel of the API 2 as output channel of API 1, I am thinking I will lose the output of the API 1.

Would you please help how this can be achieved?

Edit :

API 1(there is no need of outbound gateway as this API is doing db operations)

<int-http:inbound-gateway
            request-channel="aRequestInputChannel"
            reply-channel="aOutputChannel"
            supported-methods="POST"
            path="/perform"
            mapped-request-headers="*"
            request-payload-type="com.test.spring.integration.LPRequestPayload">
        <int-http:request-mapping consumes="application/json" />
    </int-http:inbound-gateway>

    <int:service-activator input-channel="aRequestInputChannel" ref="IBAdapterController" method="attachData" output-channel="unRequestChannel"/>

API 2:

<int-http:inbound-gateway
            request-channel="unRequestChannel"
            reply-channel="unResponseChannel"
            supported-methods="POST"
            path="/test/unOp"
            request-payload-type="com.test.spring.integration.LPRequestPayload"
            mapped-request-headers="userId, userName, languageCode, HTTP_REQUEST_HEADERS" >
        <int-http:request-mapping consumes="application/json,application/xml" />
        <int-http:header name="userId" expression="#requestParams[userId]"/>
    </int-http:inbound-gateway>

    <int:service-activator input-channel="unRequestChannel" output-channel="unOutputChannel" ref="unAdapterController" method="getUnOpDetails" />

so here if I use output-channel="unRequestChannel" of first api as request channel of API 2,

  1. I am loosing original payload as I am sending http response entity from the controller of the first api. I will need to send LPRequestPayload from first api which is not the requirement. as I am performing some db operation if first api, I need to send its response to the end user.
  2. API 2 is like some mandatory operation that needs to be done after db operation is done.

1 Answers1

0

You need to provide more info about your configuration and use-case. It is not clear if you are going to call API instead of just replying from the service activator or in addition.

You may also learn that there is no need in the reply-channel in the inbound gateways and output-channel in the last in the flow endpoint. An inbound gateway always populates a replyChannel header and an endpoint (e.g. service activator) without an output-channel is going to produce its reply message exactly into that replyChannel from headers. So, it it might be possible that your requirements are met very easy:

inbound gateway 1 > request channel 1 -> service activator -> request channel 2
inbound gateway 2 > request channel 2 -> outbound gateway 2

With this configuration it doesn't matter if you have that inbound gateway 2 or not, the outbound gateway 2 is always going to reply to the replyChannel header from a request message. Therefore in your case when you initiate request from the inbound gateway 1, the outbound gateway 2 is going to reply back to that one. If you request via inbound gateway 2, then reply will come back exactly into this request initiator. The Reply Address pattern with its power.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks for the response! I have edited the question, could you please check? – KeepItSimple Dec 12 '22 at 21:22
  • To send a `LPRequestPayload` to the seocnd API as well, you can consider to store it in the header before calling `input-channel="aRequestInputChannel"` service activator. You also may consider to use a recipilent-list-router to call those services in parallel or one by one: https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#router-implementations-recipientlistrouter – Artem Bilan Dec 12 '22 at 22:55