我有一个 spring webFlux 服务器,但尚未激活它的 SSL,它使用 HTTP/1.1 进行请求连接。另一方面,在另一个应用程序中编写了一个 spring WebClient,它可以很好地调用该服务器并接收流数据作为答案。 但问题是我读到 http/1.1 协议(protocol)不是为流式传输而设计的,它用于简单的请求和响应连接,而对于流式传输可以使用 HTTP/2。我想知道 spring webclient 如何通过 http/1.1 协议(protocol)接收流数据?是否有其他 webFlux 客户端可以使用其他编程语言通过 http 工作?(除了通过 TCP、WebSocket 和 UDP 工作的 RSocket 之外)。
最佳答案
当您正在寻找流式传输和背压支持时,您是对的,HTTP 2.0 更适合。特别是如果是用于内部通信并且您可以控制客户端,那么强烈建议使用 HTTP 2.0/RSocket 机制。
正题在HTTP 1.1中,可以通过Chunked Transfer Encoding机制来实现(这是标准机制,更多details可以网上查)
Chunked transfer encoding is a streaming data transfer mechanism available in version 1.1 of the Hypertext Transfer Protocol (HTTP). In chunked transfer encoding, the data stream is divided into a series of non-overlapping "chunks". The chunks are sent out and received independently of one another. No knowledge of the data stream outside the currently-being-processed chunk is necessary for both the sender and the receiver at any given time.
HTTP 1.1 的 Spring Webflux 实现在机制的实现方面有其细微差别。
关于java - spring WebClient 如何从使用 http/1.1 的 spring webflux 服务器接收流数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65256413/