gpt4 book ai didi

Spring Boot 2 - 将 Mono 转换为 rx.Observable?

转载 作者:行者123 更新时间:2023-12-02 09:53:04 24 4
gpt4 key购买 nike

我正在尝试将 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 :(.
}

有一个简单的方法可以做到这一点吗?

问候

最佳答案

推荐的方法是使用 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
}

关于Spring Boot 2 - 将 Mono 转换为 rx.Observable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51246247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com