【问题标题】:int-http:inbound-gateway same request Channel and different Response channel issueint-http:inbound-gateway 相同的请求通道和不同的响应通道问题
【发布时间】:2014-11-15 02:47:49
【问题描述】:

我有两个 int-http:inbound-gateway,其路径如下所述。并且指向相同的请求通道,但具有不同的回复通道。

 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”时调用“默认”网关,即不一致。或者不确定它是否可以正确调用,而是对不同的回复通道做出响应?

我正在使用 DispatcherServlet.Below my spring-integration.xml

     <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.

【问题讨论】:

  • 是但不完全是。我使用相同的请求通道和不同的响应通道。响应来自端点我正在重定向到其他通道。如果你帮助我会很棒。

标签: spring-integration


【解决方案1】:

您不应该这样配置您的回复渠道;这可能会导致不可预知的结果。

reply-channels 只是简单地桥接到消息 replyChannel 标头,因此它通常可以正常工作,但它是不可预测的,因为在网关第一次收到消息时设置了桥。

相反,只需省略网关上的 reply-channel 属性,让框架直接使用 replyChannel 标头路由回复。

配置一个“无处的桥”(&lt;bridge/&gt;input-channel= CommonResponseChannel" 而不是 output-channel

或者简单地省略最后一个端点上的output-channel(而不是发送到CommonResponseChannel)。

【讨论】:

  • 感谢加里的支持。
  • 对不起,如果我问愚蠢的问题。我不明白的是,如果我没有配置回复通道,它如何知道它应该给出哪个响应。或者我不能在 Endpoint 之后对结果进行任何修改.即我需要根据不同的路径发送不同的结果但端点是相同的,在得到结果后我将重定向到某个通道并进行一些转换并将结果放入某个通道中,该通道配置为http入站网关的回复通道。请在主帖中查看 int-http:inbound-gateway id="XYZ"
  • 你可以做任何你想做的事,但如果你有 2 个或更多网关提供相同的流,最好不要在最后一个组件上使用 output-channel - 框架知道如何将回复路由到原始网关,使用replyChannel 消息头。很少需要明确的回复通道 - 仅当您想添加一个窃听器或使其成为发布/订阅通道等时才需要。
  • 在我的情况下,我使用 2 条路径“默认”和“XYZ”。如果请求“默认”,则结果来自端点后,两条路由到 SameEndpoint(因为我只希望结果与端点相同) ) 框架使用replyChannel 进行处理。但是对于“XYZ”,在结果来自端点后,我需要转换或更改消息,实际上我需要向“XYZ”提供新消息,我现在将其放入channel="XYZResponse"会发生什么 ?由于框架使用replyChannel,它将给出与端点结果相同的“XYZ”结果。 “XYZ”不会从频道“XYZResponse”获得结果。
  • 您所拥有的应该可以正常工作,因为您正在路由到正确的回复通道;我只是更喜欢让框架处理回复路由。我建议您打开 DEBUG 日志记录并通过流程跟踪消息以查看问题所在。
猜你喜欢
  • 1970-01-01
  • 2018-09-24
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
  • 2020-07-07
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多