WebFlux在GET控制器中,我需要检查与mongo db的连接,以从Kubernates的角度验证活动,但当我断开db连接时,代码无法进入onErrorResume。为什么?可能的解决方案?
@RequestMapping("/liveness-for-kubernates/{id}")
@ResponseBody
public Mono<ResponseEntity<String>> livenessForKubernates(@PathVariable @NotBlank String id) {
return Mono.just(id)
.map(golamService::findById)
.map(result -> new ResponseEntity<String>("UP", HttpStatus.OK))
.onErrorResume(
throwable -> Mono.just(new ResponseEntity<String>("DOWN", HttpStatus.OK)));
}发布于 2021-11-18 13:48:13
findById是导致Mono发布程序的异步、非阻塞操作。因此,您应该将其包装到flatmap中,而不是map中
return Mono.just(id)
.flatmap(golamService::findById)
.map(result -> new ResponseEntity<String>("UP", HttpStatus.OK))
.onErrorResume(throwable -> Mono.just(new ResponseEntity<String>("DOWN", HttpStatus.OK)));map用于同步、非阻塞、一对一转换。
https://stackoverflow.com/questions/70020803
复制相似问题