春季集成 - 您如何轮询外部服务,直到条件为真?

发布于 2025-01-29 02:50:39 字数 426 浏览 1 评论 0原文

我有以下方案:

我将数据发送到第三方(发生的肥皂服务)。外部服务接受我的数据,并为我提供了独特的参考,然后我可以使用该参考来调用第二个SOAP服务,以查看是否处理了我的数据。

因此,我需要对第二次服务进行轮询,直到我从中得到回复,说我的数据已经准备就绪。一旦准备就绪,我的流程就可以结束(我只想写出它可以到数据库表准备的事实)。如果我进行了一定数量的轮询,并且还没有准备好,我想放弃并调用某种例外处理。

我无法弄清楚我应该用什么来进行民意测验;即,在设定的时间后再次检查我的肥皂呼叫和轮询结果的逻辑。我必须等待的时间可能是充满活力的 - 例如,所谓的第三方服务可能会说“还没有准备好,在5分钟内重试”,这样我就必须在5分钟内再次进行调查。

是否有人想到使用Java(或最好是)Kotlin DSL在春季集成中如何做上述?

我只是想解决春季集成是否是这里工作的正确工具。

I have the following scenario:

I send data to a 3rd party (a SOAP service as it happens). The external service accepts my data, and gives me a unique reference which I then can use to call a second SOAP service to see if my data has been processed.

So I need to poll the second service until I get a response back from it saying my data is ready. Once it's ready my flow can end (I just want to write the fact that it's ready to a database table). If I poll a certain number of times and it's not ready I want to give up and call some sort of exception processing.

I can't work out what I should use for the polling; i.e. the logic for checking the result of my soap call and polling again after a set amount of time. The time I have to wait could be dynamic - for example the 3rd party service that is called might say "it's not ready yet, try again in 5 minutes" so that I have to poll again in 5 minutes.

Does anyone have an idea of how I would do the above in Spring integration, using the Java (or preferably) Kotlin DSL ?

I'm just trying to work out if Spring Integration is the right tool for the job here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

你的笑 2025-02-05 02:50:39

在您的情况下,我会说的“民意调查”更像是“重复直到两者之间的延迟”。

因此,在致电第一份服务后,您将转到频道进行第二次服务。
然后,您使用route()确定是否可以,或者必须重复。此时,您发送到delay()时,确实可以从SOAP回复确定其持续时间时。在这一点上,我还将增加一些尝试标题与另一个route()查看我们是否可以重复重复或已经是时候抛出异常了。

只是不要忘记,您可以在流的中间有一个channel(),因此其他一些端点(例如路由器或延迟器)可以将消息直接发送到此频道。

可以使用普通Java来完成另一个解决方案,该解决方案将进行所有这些“重复”,直到围绕调用@messaginggateway,它将向第二个SOAP服务发送消息并等待其答复。

在文档中查看有关所有上述组件的更多信息:

https://docs.spring.io/spring-integration/docs/current/referent/referent/html/message-routing.html#router

https://docs.spring.io/spring-integration/spring-integration/docs/docs/current/current/current/referent/referent/reference/reference/html/messaging -endpoints.html#delayer

https://docs.spring.io/spring-integration/docs/current/referent/referent/html/messaging-endpoints.html#gateway

https://docsring.io/spring.io/spring-integring-intring-integration/docs/current/current/reference/reference/reference/html一下/DSL.html#java-dsl-channels

The "poll" in your case I would say is more like "repeat until with delay in between".

So, after calling the first service you go to the channel for a second service.
Then you use a route() to determine if it is OK, or has to be repeated. At this point you send to delay(), when its duration indeed can be determined from a SOAP reply. At this point I also would increase some attempts headers to check with another route() to see if we are OK to repeat or it is already time to throw an exception.

Just don't forget that you can have a channel() in the middle of the flow, so some other endpoint (like that router or delayer) can send messages directly to this channel.

Another solution could be done with plain Java which would do all these "repeat until" logic around calling a @MessagingGateway which would send a message to that second SOAP service and wait for its reply.

See more in docs about all the mentioned components:

https://docs.spring.io/spring-integration/docs/current/reference/html/message-routing.html#router

https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#delayer

https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway

https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl-channels

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