简体   繁体   中英

Spring integration asyc flow

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

I hope you use <int-http:inbound-gateway> for your REST service.

In this case you are expecting for the response in the 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 . That should really be felt organically: we don't have anything to do, so treat the absent of outputChannel as the end of flow. In case of replyChannel in headers we send our result back t othe caller. In your case into the HTTP Response.

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.

The XML config on the matter may look like:

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

Your 3rd party service should be called from that <service-activator> , who is the second subscriber to the same <publish-subscribe-channel> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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