我有一段代码,使用WebClient从Json数组结果创建一个Mono<List<T>>
。bodyToMono方法返回一个Mono<List<T>
对象,我订阅它并获取一个parallelStream
final WebClient client = WebClient.create(daemonEndpoint);
client.get()
.uri("/services?label=com.docker.stack.namespace")
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<Map<String, Object>>>() {
})
.subscribe(services -> services.parallelStream()
.map(e -> {
final String id = (String) e.get("ID");
我想知道是否有一种解决方案可以删除订阅部分。
flatMap
造成了问题,因为它必须为我创建一个发布者。我将其更改为map
,另一个监听器停止工作,所以也许这就是你选择flatMap
的原因。 - Archimedes Trajano