概括 http:outbound-gateway 回复通道
给定一个处理对 ws.service 的服务调用的网关。我的目标是使用 header-enricher
提供 http:outbound-gateway 的回复通道
,因为我将向 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>
Given a gateway that handles service calls to a ws. My goal is to supply the http:outbound-gateway's reply-channel
using header-enricher
since I'll be adding multiple methods to gateway
and I would like to make use of only 1 http:outbound-gateway
I can currently receive the response up to groovy script (2) BUT it doesn't seem to want to return the results to the actual method that calls the service
Any help would be appreciated. Thanks!
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行以下操作:
网关的每个方法都应使用一些唯一的“路由”标头值来丰富消息:
然后直接将消息发送到出站网关:
Http 出站网关将请求发送到远程服务器,然后将响应转发到
http-响应通道。该通道附加了标头值路由器,它根据路由标头的值将消息发送(路由)到适当的通道:
当然,您不需要将其直接发送回网关 - 您可以添加一些额外的处理在这些组件之间,并且您始终可以根据标头值路由消息。
它比用 groovy 进行黑客攻击更简单,而且我自己使用它 - 证明是有效的;)
Do the following:
Each method of your gateway should enrich message with some unique 'routing' header value:
And then send message straight forward to outbound gateway:
Http outbound gateway sends request to the remote server and then forward response to
http-response-channel
. To this channel is attached header value router, which basis on the value of routing header, sends (routes) message to the appropriate channel:Of course you don't need to send it back directly to the gateway - you can add some additional processing between those components, and all the time you can route message basis on the header value.
It's simpler than hacks with groovy and I use it myself - proven that works ;)