【问题标题】:Can spring webclient be used with RESTful API which is not reactive based?spring webclient 可以与不基于反应的 RESTful API 一起使用吗?
【发布时间】:2020-07-30 04:36:02
【问题描述】:

使用 WebClient 从多个非响应式的 REST API 获取响应是否存在任何问题。

【问题讨论】:

    标签: spring-webflux spring-webclient


    【解决方案1】:

    是的,你绝对可以,事实上,Spring 官方鼓励使用 WebClient。此外,通常作为基于 REST 的服务的首选通信方式的 RestTemplate 已被弃用。

    此外,在非响应式上下文中使用 WebClient 也没有问题

    https://docs.spring.io/spring/docs/5.2.8.RELEASE/spring-framework-reference/web.html#webmvc-client

    但是,在非响应式上下文中使用 WebClient 时,您必须明确调用 subscribeblock

    【讨论】:

    • 谢谢。那么使用这种方式会失去所有好处吗?与使用带有响应式 API 的 webclient 相比。
    • 即使在非反应式环境中使用 WebClient 也不会失去任何好处。
    • 异步和非阻塞的实现不是只能在响应式世界中使用吗?这就是我问的原因。
    • @Isank 请阅读stackoverflow.com/help/how-to-ask关于图片的部分,DO NOT post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text.
    猜你喜欢
    • 2018-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    相关资源
    最近更新 更多