我正在尝试将HystrixObservableCommand与Spring WebFlux WebClient一起使用,我想知道是否有一个“干净”来将Mono转换为rx.Observable。我的初始代码如下所示:
public Observable<Comment> getComment() {
return webClient.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Comment.class)
// stuff missing here :(.
}
这样做容易吗?
问候
发布于 2018-07-09 13:47:01
建议的方法是使用RxJavaReactiveStreams,更具体地说:
public Observable<Comment> getComment() {
Mono<Comment> mono = webClient.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Comment.class);
return RxReactiveStreams.toObservable(mono); // <-- convert any Publisher to RxJava 1
}
发布于 2019-09-24 19:15:38
您可以使用
Observable.fromFuture(webClient.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Comment.class).toFuture());
https://stackoverflow.com/questions/51246247
复制相似问题