我有一个尝试使用 WebClient 返回 Mono 的方法
@GetMapping("getMatch")
public Mono<Object> getMatch(@RequestParam Long matchId) {
return WebClient.create(OpenDotaConstant.BASE_URL).get()
.uri("/matches/{matchId}", matchId)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Object.class);
}
Run Code Online (Sandbox Code Playgroud)
它可以返回我期望的结果。然后我尝试创建另一种方法来支持 List 作为参数
@GetMapping("getMatches")
public Flux<Object> getMatches(@RequestParam String matchesId) {
List<Long> matchesList = JSON.parseArray(matchesId, Long.class);
return Flux.fromStream(matchesList.parallelStream().map(this::getMatch));
}
Run Code Online (Sandbox Code Playgroud)
但这次返回了一个奇怪的结果。
[
{
"scanAvailable": true
},
{
"scanAvailable": true
}
]
Run Code Online (Sandbox Code Playgroud)
我是反应式编程的新手,结合 Stream 和 Mono,然后转换为 Flux 的正确方法是什么?