我正在使用RxJava异步调用第三方Web服务API。我正在使用Single创建可观察的。在运行代码时,我发现控制器返回的ReponseEntity类型很好,但是,当我将其更改为Single时,控制器不会返回响应,并且请求将永远等待。这是代码块:
Configurations: rxjava2, SpringBoot 2.0.6.RELEASE, rxjava-reactive-streams 1.2.1
Works:
//RxJava
@GetMapping(value = "/getBook/{bookNumber}", produces = "application/json")
public ResponseEntity<String> getBookAsync(@PathVariable(value = "bookNumber")
String bookNumber, @RequestHeader(name = ConstantsUtility.CORRELATION_ID,
required = true) final String correlationId) {
return new ResponseEntity<>("single value", HttpStatus.CREATED);
}
无响应,请求永远等待
//RxJava
@GetMapping(value = "/getBook/{bookNumber}", produces = "application/json")
public Single<ResponseEntity<String>> getBookAsync(@PathVariable(
value = "bookNumber")
String bookNumber, @RequestHeader(name = ConstantsUtility.CORRELATION_ID, required = true) final String correlationId){
return Single.just(new ResponseEntity<>("single value", HttpStatus.CREATED));
}
对此表示感谢! 谢谢