【问题标题】:Spring integration - need immediate response from webservice gateway with asynchronous processing in backendSpring 集成 - 需要来自 Web 服务网关的即时响应,并在后端进行异步处理
【发布时间】:2015-05-12 13:07:03
【问题描述】:

我们有一个要求,外部客户端正在调用我们的 Spring 集成入站 Web 服务网关之一,我们需要立即以一般的 OK 状态确认它们。同时,payload会被提交到一个channel进行异步处理,我们不需要response(根据一些业务验证发送email)。

我们尝试使用异步网关和执行器通道(带有任务执行器),但无法弄清楚如何使网关立即响应。在这两种情况下,它都作为单向 Web 服务运行,没有响​​应。

配置:

<context:component-scan base-package="com.myapp.springintegration" />



<channel id="helloWorldRequestChannel">
    <dispatcher task-executor="taskExecutor"/>
</channel>
<channel id="helloWorldReplyChannel"/>

<task:executor id="taskExecutor" pool-size="2"/>

<gateway id="helloServiceGateway" 
 service-interface="com.myapp.springintegration.HelloService"
 default-request-channel="helloWorldRequestChannel" default-reply-channel="helloWorldReplyChannel"/>

 <service-activator input-channel="helloWorldRequestChannel" ref="helloServiceImpl" method="hello" />

【问题讨论】:

    标签: java web-services asynchronous spring-integration


    【解决方案1】:

    我没有看到任何&lt;int-ws:inbound-gateway&gt;,但要求可以这样实现:

    <int-ws:inbound-gateway request-channel="requestChannel"/>
    
    <int:recipient-list-router input-channel="requestChannel">
        <int:recipient channel="response" />
        <int:recipient channel="process" />
    </int:recipient-list-router>
    
    <int:transformer input-channel="response" expression="'OK'"/>
    
    <int:channel id="process">
       <int:dispatcher task-executor="testExecutor"/>
    </int:channel>
    

    您向recipient-list-router 发送请求,该recipient-list-router 将您的消息分发到另外两个渠道。第一个(response)只是立即向 WS 返回简单的回复。第二个 (process) 将消息转移到单独的 Thread,因此该频道的订阅者将在不阻塞 WS Thread 的情况下完成其工作。

    希望我清楚。

    【讨论】:

    • 感谢@Artem 的回复,但变压器将在哪里回复。我们需要网关的回复通道吗?
    • 大多数情况下不需要。无论如何,对于任何入站网关,它都是MessageHeaders 中的TemporaryReplyChannel。当您应该对正常回复做一些额外的工作时,需要此类网关上的reply-channel,例如使用&lt;publish-subscribe-channel&gt; 将回复发送到其他流。
    • 为什么需要 2 个频道?难道不能只有一个通道并让它在单独的线程上执行吗?
    • 如果您有任何问题,请在单独的 SO 线程上提出
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多