概括 http:outbound-gateway 回复通道

发布于 2024-11-30 10:29:26 字数 1487 浏览 2 评论 0原文

给定一个处理对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一向肩并 2024-12-07 10:29:26

执行以下操作:

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

<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-响应通道。该通道附加了标头值路由器,它根据路由标头的值将消息发送(路由)到适当的通道:

<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 进行黑客攻击更简单,而且我自己使用它 - 证明是有效的;)

Do the following:

Each method of your gateway should enrich message with some unique 'routing' header value:

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

And then send message straight forward to outbound 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 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:

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

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 ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文