java - Spring Webflux 在一个 Flux 中等待一个 Flux
问题描述
这是场景,我有一个来自 ReactiveMongoDB 和另一个来自 WebClient 的 Flux,所以我需要对于 Mongodb 中的每个项目,我在 webclient 中查找他的项目。
问题是,我一直在使用块来等待 webclient 的到来,这会影响性能。
如果我不使用 Block,则在没有来自 webClient 的 itens 的情况下发送响应,所以它可能不会等待这个 itens 来。
有什么方法可以拨打所有电话并稍后再等待?
return planetaRepository.findAll().flatMap(planetaVO -> {
planetaServiceFacade.recuperarFilmesParticipados(planetaVO.getNome()).collectList().doOnNext(planetaVO::setFilmes).block();
return Flux.just(planetaVO);
});
解决方案
你可以尝试这样的事情,通过使用thenReturn
return planetaRepository.findAll().flatMap(planetaVO -> {
return planetaServiceFacade.recuperarFilmesParticipados(planetaVO.getNome()).collectList()
.doOnNext(planetaVO::setFilmes)
.thenReturn(planetaVO);
});
如果你不是被迫的话,我建议你不要用你的母语编写代码。
推荐阅读
- asp.net - 如何将用户数据从视图传递到控制器并返回一个罗马数字
- c# - 将绑定从一个属性“转移”到另一个
- reactjs - github页面没有从部署的React App中的服务器加载文件
- python - Winsound 导致我的 tkinter GUI 打开缓慢
- java - 监视服务器上文件更改的 Java 应用程序
- python - 在 python 中安装 dtaidistance 提供错误
- c++ - 函数参数与传递的参数不同
- sorbet - 如何在 Sorbet 中键入实例变量缓存?
- python - 如何使用 Python 组合 JSON 数据的相同键的所有值
- python - WTFforms:如何避免 NumberRange 验证器中的大整数溢出错误?