响应式WebClient与同步依赖REST调用

huangapple go评论77阅读模式
英文:

Reactive WebClient with synchronous dependency REST call

问题

在实现Service C的A和B的提供者时,是否都应该返回Monos?Service A是同步的是否重要?我的假设是Service A的实现方式不应该重要。在Service C中,我们使用WebClient框架异步发起调用,并在响应准备好时进行订阅。所以A和B都应该被处理为Mono。

有人可以确认这个假设是否正确,或者Service A是否应该以不同的方式处理。谢谢。

英文:

Lets say I have a Service C that makes 2 dependency calls (both dependent services are implemented with Spring Boot):

  1. Service A - A REST API endpoint that does not return a Mono, so its a synchronous call
  2. Service B - A REST API endpoint that returns a Mono, so its an asynchronous call

When are are implementing the providers in Service C for A and B using WebClient, should both return Monos? Does it matter that Service A is synchronous? My assumption is that it shouldn't matter how Service A is implemented. In Service C, a Mono, we are letting WebClient framework make the call asynchronously and are subscribing a response when it is ready. So both A and B should be handled as a Mono.

Can anyone confirm if this assumption is correct, or if Service A should be handled differently. Thanks.

答案1

得分: 1

你说得对。无论服务A如何实现,你都可以使用响应式客户端。如果你的应用程序(服务C)是响应式的,甚至可以期望你这样做。

英文:

You are right. No matter how service A is implemented, you could use a reactive client. You even are expected to do so if your application (service C) is reactive.

huangapple
  • 本文由 发表于 2023年6月30日 03:32:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76584122.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定