spring-webflux - 读取 Part Flux 时传递状态
问题描述
我有一个使用 Webflux 的 Boot 2.x 应用程序,我正在Parts
使用@RequestBody Flux<Part>
.
我的问题是我需要读取第一个Part
,使用其中的内容初始化一个对象Part
,然后传递该对象以在第二个中使用Part
。在确保阅读可用的每个部分的同时,我该如何做呢?
我目前的解决方案是使用groupBy
,但这样做会触发等到所有部分完成,这是不可接受的。
这是我正在尝试做的一个例子:
parts.scan( new Foo(), (foo, part) -> {
if(part.name().equalsIgnoreCase("first_part"))
{
Jackson2JsonDecoder jackson2JsonDecoder = new Jackson2JsonDecoder();
Mono<Metadata> metadata = jackson2JsonDecoder.decodeToMono(part.content(), ResolvableType.forClass(Metadata.class), null, null);
// Here's my problem. How do I call foo.init(metadata) in a non-blocking way while still returning foo so it can be used by the next part?
}
else if(part.name().equalsIgnoreCase("second_part"))
{
// Use initialized foo from part 1 to push second_part's DataBuffer Flux
}
});
谢谢!
解决方案
推荐阅读
- ios - LSApplicationQueriesSchemes 在自定义框架中不起作用
- jquery - 对话框未在 jquery 中以适当的高度显示
- angular - 如何在Angular 7中通过正则表达式显示数据过滤器
- sql-server - 如何使用递归 CTE 从 00 到 23 获取时间?
- java - 这是实现并发的正确方法吗?
- php - laravel 日期/时间问题
- spring-boot - 迁移到有命名冲突的 @ConfigurationProperties
- javascript - 如何修复“未捕获(承诺)DOMException:play()”
- intellij-idea - Intellij 不保存未知文件类型的本地历史记录?
- java - GIS - 计算两点之间的距离时得到奇怪的结果