【问题标题】:Generalize http:outbound-gateway reply-channel泛化 http:outbound-gateway 回复通道
【发布时间】:2011-08-20 05:04:39
【问题描述】:

给定一个网关来处理对 ws 的服务调用。我的目标是使用header-enricher 提供http:outbound-gateway's reply-channel,因为我将向gateway 添加多种方法,并且我只想使用1 个http:outbound-gateway

我目前可以接收到 groovy 脚本 (2) 的响应,但它似乎不想将结果返回给调用服务的实际方法

任何帮助将不胜感激。谢谢!

<gateway id="registryService" service-interface="RegistryService">
<method name="create" request-channel="create-request-channel"
        reply-channel="create-reply-channel" />
</gateway>

<chain input-channel="create-request-channel" output-channel="create-request-fulfillment-channel">
 <transformer>
   // groovy script that contains the method to be called in the ws (1)
 </transformer>
 <object-to-json-transformer/>
 <header-enricher>
   <reply-channel overwrite="true" ref="create-reply-fulfillment-channel" />
 </header-enricher>
</chain>

<http:outbound-gateway request-channel="create-request-fulfillment-channel"
                       extract-request-payload="true"
                       expected-response-type="java.lang.String"
                       url="http://localhost:4567" http-method="POST" />

<chain input-channel="create-reply-fulfillment-channel"
       output-channel="create-reply-channel">
       <json-to-object-transformer type="JsonRpcResponse"/>
       <transformer>
           //groovy script to manipulate response (2)
       </transformer>
</chain>

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    执行以下操作:

    网关的每个方法都应该使用一些独特的“路由”标头值来丰富消息:

    <gateway id="registryService" service-interface="RegistryService">
      <method name="create" request-channel="http-request-channel"
            reply-channel="registryService-create-responseChannel">
        <header name="routingHeader" value="registryService-create" />
      </method>
    </gateway>
    

    然后将消息直接发送到出站网关:

    <http:outbound-gateway request-channel="http-request-channel"
                           response-channel="http-response-channel"
                           extract-request-payload="true"
                           expected-response-type="java.lang.String"
                           url="http://localhost:4567" http-method="POST" />
    

    Http 出站网关向远程服务器发送请求,然后将响应转发到http-response-channel。该通道附加了头值路由器,它根据路由头的值将消息发送(路由)到适当的通道:

    <header-value-router input-channel="http-response-channel" header-name="routingHeader">
      <mapping value="registryService-create" channel="registryService-create-responseChannel" />
      <mapping value="someOtherService-otherMethod" channel="someOtherService-otherMethod-responseChannel" />
    </header-value-router>
    

    当然,您不需要将其直接发送回网关 - 您可以在这些组件之间添加一些额外的处理,并且始终可以根据标头值路由消息。

    它比 groovy 的 hack 更简单,我自己使用它 - 证明有效;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多