从另一个API调用http rest API



我有API 1,它由int-http:inbound-gateway定义,并具有服务激活器来执行一些业务逻辑,并在与入站网关(简单流)的应答通道相同的输出通道上发送输出

我也有API 2,它定义在不同的xml文件中,它也有int-http:inbound-gateway和int-http:outbound-gateway,它们自己执行。

现在我想从API 1调用API 2,但我不想将第一个API 1的输出通道的消息发送到API 2, API 1的输出通道响应如果供最终用户消费!如果我使用API 2的请求通道作为API 1的输出通道,我认为我将失去API 1的输出。

你能帮我怎么做吗?

编辑:

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" />

所以这里如果我使用output-channel="unRequestChannel"第一个api作为api 2的请求通道

  1. 当我从第一个api的控制器发送http响应实体时,我正在失去原始有效载荷。我需要从第一个api发送LPRequestPayload,这不是要求。因为我正在执行一些数据库操作,如果第一个api,我需要将其响应发送给最终用户。
  2. API 2就像一些强制操作,需要在db操作完成后进行。

您需要提供有关您的配置和用例的更多信息。目前还不清楚你是否要调用API,而不是仅仅从服务激活器回复。

您还可以了解到,入站网关中的reply-channel和流端点中的最后一个output-channel都不需要。入站网关总是填充replyChannel标头,而没有output-channel的端点(例如服务激活器)将准确地从标头生成其回复消息到replyChannel。所以,如果你的要求很容易就能满足的话:

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

有了这个配置,不管你是否有inbound gateway 2,outbound gateway 2总是会从请求消息中回复replyChannel头。因此,在您的情况下,当您从inbound gateway 1发起请求时,outbound gateway 2将回复该请求。如果您通过inbound gateway 2请求,那么应答将准确地返回到该请求发起者。Reply Address模式与它的力量。

最新更新