简体   繁体   English

Spring Integration Asyc流程

[英]Spring integration asyc flow

我对我的spring集成项目有一个要求,即在用户进行静息呼叫时需要提供状态,对此呼叫服务器进行一些处理n计算应重新调整的状态,如果状态为成功,那么我需要打电话给第三方服务,但这对用户是透明的(第三方应该是异步的)如何在Spring集成中实现

I hope you use <int-http:inbound-gateway> for your REST service. 我希望您将<int-http:inbound-gateway>用于REST服务。

In this case you are expecting for the response in the TemporaryReplyChannel . 在这种情况下,您期望在TemporaryReplyChannel获得响应。

Typically reply transparently we should just use that channel from header. 通常,透明地答复我们应该只使用标头中的该通道。

All Spring Integration request-reply component do that when they aren't supplied with the outputChannel . 当未提供outputChannel时,所有Spring Integration请求-答复组件都将执行此outputChannel That should really be felt organically: we don't have anything to do, so treat the absent of outputChannel as the end of flow. 真正应该有机地感觉到这一点:我们没有任何事情要做,因此将outputChannel的缺失视为流的结尾。 In case of replyChannel in headers we send our result back t othe caller. 如果标题中有replyChannel ,我们会将结果发送回给调用者。 In your case into the HTTP Response. 在您的情况下进入HTTP响应。

Looks like that works for you already now. 看起来现在已经适合您。

To achieve your async requirements I'd suggests something like PublishSubscribeChannel with the TaskExecutor to be able to send the same message to several subscribers and do that in parallel manner. 为了满足您的异步要求,我建议使用TaskExecutor类的PublishSubscribeChannel之类的PublishSubscribeChannel ,以便能够将相同的消息发送给多个订阅者,并以并行方式进行。

The XML config on the matter may look like: 此事的XML配置看起来可能像这样:

<service-activator input-channel="lastProcessChannel" output-channel="3rdPartyChannel"/>

<publish-subscribe-channel id="3rdPartyChannel" task-executor="taskExecutor"/>

<bridge input-channel="3rdPartyChannel"/>

<service-activator input-channel="3rdPartyChannel"/>

Independently of that executor the <int-http:inbound-gateway> will wait for the reply, so it won't hurt that our async <bridge> will produce the result into the replyChannel from a different Thread. 独立于该executor<int-http:inbound-gateway>将等待答复,因此我们的async <bridge>将从另一个线程将结果生成到replyChannel也不会造成伤害。

Your 3rd party service should be called from that <service-activator> , who is the second subscriber to the same <publish-subscribe-channel> . 您的第三方服务应从该<service-activator>调用,该<service-activator>是同一<publish-subscribe-channel>的第二个订阅<publish-subscribe-channel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM