使用 Spring 和 Reactor Project 将多个 api 调用压缩为聚合结果。带有 Mono.empty() 参数的 Mono.zip() 可以返回空结果吗?
Mono<Dog> dogMono = dogApiClient.getDog(); // can return Mono.empty()
Mono<Cat> catMono = catMono = catApiClient.getCat(); // can returnMono.empty()
Mono<Horse> horseMono = horseApiClient.getHorse(); // can return Mono.empty()
Mono.zip(dogMono, dogMobo, horseMono)
.map(this::mapToAnimals);
预期结果:
{
dog: null, // if dog is null
cat: null, // if cat is null
horse: null, // if horse is null
}
实际结果:
{
dog: {
name: null,
surname: null
},
cat: {
name: null,
surname: null
},
horse: {
name: null,
surname: null
}
}
或者
"" // empty
红颜莎娜
喵喵时光机
相关分类