Flux
an Asynchronous Sequence of 0-N Items(是一个异步的处理序列,它有0或者多个条目)
官方对Flux的原理解析图解:
Spring Gateway的源码中重度依赖Reactor Project,比如:
1 | return responseFlux.then(chain.filter(exchange)); |
这句代码的逻辑会这么走:要等到responseFlux被subscribe了之后,chain.filter(exchange)(这是一个Mono),才会被继续流转运行。
Mono
Mono.just
I mean that calling Mono.just(System.currentTimeMillis()) will immediately invoke the currentTimeMillis() method and capture the result
1 | Mono<Long> clock = Mono.just(System.currentTimeMillis()); |
Mono.defer
The defer operator is there to make this source lazy, re-evaluating the content of the lambda each time there is a new subscriber:
1 | Mono<Long> clock = Mono.defer(() -> Mono.just(System.currentTimeMillis())); |