在基于Spring Boot Webflux的微服务中,订户是谁? [英] In spring boot webflux based microservice, who is the subscriber?

查看:182
本文介绍了在基于Spring Boot Webflux的微服务中,订户是谁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这里是从反应流规范中使用术语订户"和订阅".

Note: Here the terms Subscriber and Subscription are being used from the reactive streams specification.

在基于spring boot webflux的微服务中考虑以下@RestController方法.

Consider the following @RestController methods in a spring boot webflux based microservice.

    @GetMapping(path = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
    public Flux<TradingUser> listUsers() {
        return this.tradingUserRepository.findAll();
    }

    @GetMapping(path = "/users/{username}", produces = MediaType.APPLICATION_JSON_VALUE)
    public Mono<TradingUser> showUsers(@PathVariable String username) {
        return this.tradingUserRepository.findByUserName(username);
    }

  1. 谁/什么"将充当订户"? 我假设Spring Boot框架提供了一个Subscriber(?) 有人可以提供详细信息或与此相关的任何链接吗?

  1. Here "who/what" will act as the "Subscriber"? I assume the spring boot framework provides a Subscriber(?) Can someone please provide details or any links around this?

说我要使用诸如postman/curl/browser之类的客户端来调用上述宁静的端点,那么在这种情况下,客户端如何向响应服务器发出需求信号? (只有Subscriber在Subscription对象上具有使用request(n)方法来发出需求信号的句柄.但是,由于Subscriber可能也在Spring Boot框架实现的服务器端,因此实际的客户端如何发出信号?)我显然缺少了一些东西.

Say I am invoking the restful endpoint above using client like postman/curl/browser, then in that case how can the client signal demand to the reactive server? (Only the Subscriber has a handle on the Subscription object with the request(n) method to signal demand. However, since Subscriber is probably also on the server side implemented by the spring boot framework, how can the actual client signal the demand?) I am obviously missing something.

推荐答案

当前使用HTTP时,确切的反压信息不会通过网络传输,因为HTTP协议不支持此功能.如果我们使用其他有线协议,这可能会改变.

Currently with HTTP, the exact backpressure information is not transmitted over the network, since the HTTP protocol doesn't support this. This can change if we use a different wire protocol.

因此,响应流需求在HTTP级别上转换为实际的读/写.

So the reactive streams demand is translated to/from the actual read/writes at the HTTP level.

如果查看Spring Framework的org.springframework.http.server.reactive.ServletHttpHandlerAdapter,您会看到该类在Servlet 3.1异步I/O和响应流之间进行了调整.它确实实现了特定的Subscriber类.

If you looks at Spring Framework's org.springframework.http.server.reactive.ServletHttpHandlerAdapter, you'll see that this class does the adaptation between Servlet 3.1 Async I/O and Reactive Streams. It does implement a specific Subscriber class.

还有其他特定的适配器实现:Undertow,Jetty,Tomcat,Reactor Netty.如果底层服务器支持响应流,我们将简单地让服务器处理需求.如果不是,则使用Subscriber实现.

There are other specific adapter implementations for this as well: Undertow, Jetty, Tomcat, Reactor Netty. If the underlying server supports reactive streams, we'll simply let the server handle the demand. If not, a Subscriber implementation is used.

这篇关于在基于Spring Boot Webflux的微服务中,订户是谁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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