Spring integration int http:入站网关相同的请求通道和不同的响应通道问题
我有两个int http:inbound网关,路径如下所述。它们指向相同的请求通道,但有不同的回复通道Spring integration int http:入站网关相同的请求通道和不同的响应通道问题,spring-integration,Spring Integration,我有两个int http:inbound网关,路径如下所述。它们指向相同的请求通道,但有不同的回复通道 http://localhost:8080/XYZ/ABCService/query -- i expected to call http:inbound-gateway with id ="XYZ" http://localhost:8080/ABCService/query - i expected to call http:inbound-gateway with id
http://localhost:8080/XYZ/ABCService/query -- i expected to call http:inbound-gateway with id ="XYZ"
http://localhost:8080/ABCService/query - i expected to call http:inbound-gateway with id ="default"
但是,当我向你提出请求时,它的不一致性又发生了什么呢
http://localhost:8080/XYZ/ABCService/query
它在调用XYZ时调用默认网关,即不一致。或者不确定它是否可以正确调用,而是对不同的应答通道进行响应
我正在使用spring-integration.xml下面的DispatcherServlet
<int-http:inbound-gateway id="default"
path="/*Service/query"
request-channel="RequestChannel" reply-channel="ResponseChannel"
supported-methods="POST" reply-timeout="5000" request-payload-type="java.lang.String"
error-channel="ErrorChannel" mapped-request-headers="xyz-*, HTTP_REQUEST_HEADERS">
<int-http:header name="reply-type" expression="'DEFAULT'" />
</int-http:inbound-gateway>
<int-http:inbound-gateway id="XYZ"
path="/XYZ/*Service/query"
request-channel="RequestChannel" reply-channel="XYZExportTransformedChannel"
supported-methods="POST" reply-timeout="5000" request-payload-type="java.lang.String"
error-channel="ErrorChannel" mapped-request-headers="xyz-*, HTTP_REQUEST_HEADERS">
<int-http:header name="reply-type" expression="'ABC'" />
</int-http:inbound-gateway>
<!--All endpoints output chanlle is CommonResonseChannel -->
<int:channel id="CommonResponseChannel">
</int:channel>
<!-- final router -->
<int:header-value-router input-channel="CommonResponseChannel"
header-name="reply-type">
<int:mapping value="DEFAULT" channel="ResponseChannel" />
<int:mapping value="ABC" channel="XYZResponseChannel" />
</int:header-value-router>
<int:channel id="ResponseChannel">
</int:channel>
<int:channel id="XYZResponseChannel">
</int:channel>
<int:transformer input-channel="XYZResponseChannel"
output-channel="XYZExportTransformedChannel" id="TransformerChannel"
ref="objToCSVTransformer"></int:transformer>
<bean class="SomeTransformer"
id="objToCSVTransformer"></bean>
<int:channel id="XYZExportTransformedChannel" />
I have opened this question before not not very clear.Not sure how to update that.So opened new one.
您不应该以这种方式配置回复通道;它可能会导致不可预测的结果 回复通道只是简单地桥接到消息replyChannel头,因此它通常可以正常工作,但这是不可预测的,因为桥接是在网关第一次收到消息时设置的 相反,只需省略网关上的应答通道属性,让框架直接使用replyChannel头路由应答 使用输入通道=CommonResponseChannel且无输出通道来配置网桥,而不是路由器
或者干脆省略最后一个端点上的输出通道,而不是发送到CommonResponseChannel。可能是重复的,但不完全是重复的。我使用相同的请求通道和不同的响应通道。此外,响应来自端点,我将重定向到其他通道。如果您提供帮助,我将非常高兴。感谢Gary的支持。如果我问了一些愚蠢的问题。我不明白的是,如果我没有配置回复通道,它如何知道应该给出哪个响应。或者我不能在端点后对结果进行任何修改。例如,我需要根据不同的路径发送不同的结果,但端点是相同的,在得到结果之后,我将重定向到某个通道,并进行一些转换,并将结果放入某个通道中,该通道被配置为http入站网关的应答通道。请参阅main post中的int http:inbound gateway id=XYZ您可以做任何您想做的事情,但是如果您有两个或更多的网关提供相同的流,最好在最后一个组件上关闭输出通道-框架知道如何使用replyChannel消息头将回复路由到原始网关。很少需要显式回复通道-仅当您要添加有线抽头时才需要,或者将其设置为发布/订阅频道等。在我的示例中,我使用2路径默认值和XYZ。如果请求默认值,则结果之后两个路由到SameEndpoint都来自端点,因为我只希望结果与端点相同。框架使用replyChannel处理。但是对于XYZ,结果之后来自端点,我需要转换或更改消息我真的需要给XYZ一个新的信息,我把它放在channel=XYZResponse中,现在会发生什么?由于框架使用replyChannel,它将给出与端点结果相同的XYZ结果。XYZ不会从通道XYZResponse获得结果。您所拥有的应该可以正常工作,因为您正在路由到正确的回复通道;我只是更喜欢让框架处理回复路由。我建议您打开调试日志记录,并通过流跟踪消息,以查看出了什么问题。