Spring 使用 RSocket 的 WebFlux:Kotlin 协程 Flow 与 Reactor Flux 消息格式

Spring WebFlux using RSocket: Kotlin coroutines Flow vs Reactor Flux message format

当我们使用 Spring WebFlux 的 RSocket(通过 WebSockets)支持使用 Kotlin Coroutines Flow 和 Reactor Flux 发出值时,IO 流量有什么不同吗?

@MessageMapping("stream")
suspend fun send(): kotlinx.coroutines.flow.Flow<SomeClass> = ...

VS

@MessageMapping("stream")
fun send(): reactor.core.publisher.Flux<SomeClass> = ...

此外,客户端代码(带有 rsocket-websocket-client 的 JS)是否应该根据服务器使用 Kotlin Coroutines Flow 还是 Reactor Flux 而有所不同?

不,它们应该是一样的。 Spring 应该注意它们之间的差异。也就是说,如果您发现任何错误,您应该提出它们。

客户端代码应该不可能观察到服务器是使用 Flux 还是 Flow 定义的。除此之外,希望客户端也不知道服务器的实现语言。

我认为您的第一个示例也不需要暂停,因为无论如何 Flow 通常都是冷的。 https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/

The Flow interface does not carry information whether a flow is a cold stream that can be collected repeatedly and triggers execution of the same code every time it is collected, or if it is a hot stream that emits different values from the same running source on each collection. Usually flows represent cold streams