简体   繁体   English

Spring Reactive Web Framework客户端

[英]Spring Reactive Web Framework Client

I was experimenting with reactive web framework.I have certain question regarding how it will work. 我正在尝试使用响应式Web框架。关于它如何工作我有一定的疑问。

In typical application,we have datastore(Relational or No SQL). 在典型的应用程序中,我们有数据存储区(关系型或无SQL)。 Application Layer(Controllers) to connect to store and get the Data. 应用程序层(控制器)进行连接以存储和获取数据。 Client Layer(Calls your API End Points) and get the data. 客户端层(调用您的API端点)并获取数据。

To best of my knowledge,there are no async or reactive drivers published by Vendors.Only Mongo and may be Cassandra has reactive drivers). 据我所知,没有由Vendors发布的异步或反应式驱动程序。只有Mongo和Cassandra可能有反应式驱动程序。 Controller layer will beam back the data using Mono or Flux or Single. 控制器层将使用Mono或Flux或Single传回数据。

Client layer will be consuming this data. 客户端层将使用此数据。

Since HTTP is synchronous in nature,how will client layer or application benefit from reactive support in Spring. 由于HTTP本质上是同步的,因此客户端层或应用程序如何从Spring的响应式支持中受益。

Question:Let us says I have 10 records in JSON coming from my Flux response.Does it mean,my client will get data in stream or entire data set will be fetched first at client side and then process of consuming it will be reactive in nature.Currently ,we have InputStream as a response of service call,which is blocking in nature,due to design of HTTP protocol. 问题:让我们说我有10条来自Flux响应的JSON记录。这意味着我的客户端将获取流中的数据,或者首先在客户端获取整个数据集,然后使用它的过程本质上是反应性的当前,由于HTTP协议的设计,我们将InputStream作为服务调用的响应,该响应本质上是阻塞的。

Question:Does it then make sense to have reactive architecture for typical web application,when very medium on which we are going to get response is Blocking in Nature. 问题:当我们要获得响应的媒介是“自然界中的障碍”时,为典型的Web应用程序配备响应式架构是否有意义?

Spring Web Reactive makes use of Servlet 3.1 non-blocking I/O and runs on Servlet 3.1 containers. Spring Web Reactive使用Servlet 3.1非阻塞I / O并在Servlet 3.1容器上运行。 It also runs on non-Servlet runtimes such as Netty and Undertow. 它还可以在非Servlet运行时(例如Netty和Undertow)上运行。 Each runtime is adapted to a set of shared, reactive ServerHttpRequest and ServerHttpResponse abstractions that expose the request and response body as Flux with full backpressure support on the read and the write side. 每个运行时都适用于一组共享的,反应性的ServerHttpRequest和ServerHttpResponse抽象,这些抽象将请求和响应主体显示为Flux,并在读取和写入侧提供了完全的反压支持。

Source: https://docs.spring.io/spring-framework/docs/5.0.0.M1/spring-framework-reference/html/web-reactive.html 来源: https : //docs.spring.io/spring-framework/docs/5.0.0.M1/spring-framework-reference/html/web-reactive.html

Datastore vendors and OSS communities are working on that. 数据存储供应商和OSS社区正在为此工作。 There's already support for Cassandra, Couchbase, MongoDB and Redis in Spring Data Kay. Spring Data Kay中已经支持Cassandra,Couchbase,MongoDB和Redis。

I think you're conflating the HTTP protocol itself and blocking Java APIs. 我认为您是在混合HTTP协议本身并阻止Java API。 You're not getting the full HTTP request or response in one big block, so the HTTP procotol is not synchronous. 您不会在一个很大的块中就获得完整的HTTP请求或响应,因此HTTP协议不是同步的。 The underlying networking library you choose also drives the choice between blocking or non-blocking I/O. 您选择的基础网络库也会驱动阻塞I / O或非阻塞I / O。

Now about your HTTP client question: if you're using WebClient , the returned Flux will emit elements as soon as they're available. 现在有关您的HTTP客户端问题:如果您使用的是WebClient ,则返回的Flux将在元素可用时立即发出。 The underlying libraries are reading and decoding messages as soon as possible, while still respecting backpressure. 基础库正在尽快读取和解码消息,同时仍要注意背压。

I'm not sure I get your last question - but if you're wondering when and why you should use a reactive approach: this approach has benefits if you're already running into scalability/efficiency issues, or if your application is communicating with many external services and is then sensitive to latency. 我不确定我是否有最后一个问题-但是如果您想知道何时和为什么应该使用被动方法:如果您已经遇到了可伸缩性/效率问题,或者如果您的应用程序正在与之通信,则此方法会有所帮助许多外部服务,然后对延迟很敏感。 See more about that in the Spring Framework 5.0 FAQ . Spring Framework 5.0 FAQ中查看有关此内容的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM