在Webflux中运行顺序操作



我有两个服务,我想以顺序的方式背靠背调用。它们都不产生任何数据。将它们链接到webflux管道中的最佳方式是什么。

我想在最后一个服务调用上调用subscribe来触发整个流。类似于:

serviceA.methodX()
.then()
serviceB.methodY().subscribe()

这就是我认为的替代方案:

Mono.just(Boolean.TRUE)
.flatMap( success -> { serviceA.methodX(); return true; } )
.flatMap( success -> { serviceB.methodY(); return true; } )
.subscribe();
Mono<OfSomeThing> executeFirst = ... ;
Mono<OfSomeThing> onceFirstIsCompletedExcecuteSecond = ... ;
Mono<OfSomeThing> plan = executeFirst.then(onceFirstIsCompletedExcecuteSecond);
plan.block();

最新更新