通用http:outbound-gateway回复通道

时间:2011-08-20 05:04:39

标签: spring-integration

给定一个处理对ws的服务调用的网关。我的目标是使用http:outbound-gateway's reply-channel提供header-enricher,因为我将向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>

1 个答案:

答案 0 :(得分: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>

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

它比常规的黑客更简单,我自己使用它 - 证明有效;)