Spring-WebFlux

Spring-WebFlux 相关笔记

Reactive Streams、Reactor 和 Web Flux关系

Reactive Streams 是规范 Reactor 实现了 Reactive Streams Web Flux 以 Reactor 为基础,实现 Web 领域的反应式编程框架。

使用 Spring 5 的 WebFlux 开发反应式 Web 应用 https://www.ibm.com/developerworks/cn/java/spring5-webflux-reactive/index.html

Spring Reactor 入门与实践 https://www.jianshu.com/p/7ee89f70dfe5


WebClient

block()/blockFirst()/blockLast() are blocking, which is not supported in thread

WebClient.post 发送 HTTP 请求报错:

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-kqueue-3
    at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83)
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ HTTP POST "/actuator/route/taskAgent" [ExceptionHandlingWebHandler]
Stack trace:
        at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83)
        at reactor.core.publisher.Mono.block(Mono.java:1703)

有时候报错的是 epoll 线程
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-epoll-142

原因: 包了两层 mono,block 出错 去掉 block