谁在响应式 Web 应用程序中调用 Flux 或 Mono 上的订阅 [英] who calls subscribe on Flux or Mono in reactive webapplication

查看:42
本文介绍了谁在响应式 Web 应用程序中调用 Flux 或 Mono 上的订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些响应式 Web 应用程序的示例,我看到它们是这样的

I am looking at some examples of reactive web applications and i am seeing them like this

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody    
public Mono<Person> findById(...) {
    return exampleService.findById(...);
}

@RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ResponseBody
public Flux<Person> findAll() {
    Flux<Person> persons = exampleService.findAll();
    return persons;
}

当我阅读文档中提到的 Mono 和 Flux 时,必须调用 subscribe 来让 Mono 或 Flux 发出数据.

When i am reading about the Mono and Flux in the documentation it mentioned subscribe has to be called for Mono or Flux to emit the data.

因此,当我在本地运行这些反应式 Web 应用程序并在我点击端点时使用邮递员/chrome 浏览器时,我得到了结果.

So when i run these reactive webapplications locally and using postman/chrome browser when i hit the endpoints i getting the results.

在服务端,虽然端点返回 Mono 或 Flux,但我如何在浏览器/邮递员中看到实际结果.每当我点击返回 Mono/Flux 类型的端点时,浏览器是否会在内部调用 subscribe ?

On the service side though endpoints are returning Mono or Flux, how i am seeing the actual results in the browser/postman. Is the browser doing the part of calling the subscribe internally whenever i am hitting the endpoints that return Mono/Flux types?

推荐答案

MonoFlux 概念仅存在于您的应用程序中,而 HTTP 协议用于在您的应用程序之间进行通信.邮递员/chrome 应用程序和您的应用程序.
Spring Webflux 框架的内部类订阅控制器方法返回的 MonoFlux 实例,并根据 MediaType 将它们映射到 HTTP 数据包您在 RequestMapping 中指定.

Mono and Flux concepts exist only within your application, while HTTP protocol is used to communicate between your postman/chrome app and your application.
Internal classes of the Spring Webflux framework subscribe to Mono and Flux instances returned by your controller methods and map them to HTTP packets based on the MediaType that you specified in RequestMapping.

这篇关于谁在响应式 Web 应用程序中调用 Flux 或 Mono 上的订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆