Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么webClient不';不做任何http调用?_Java_Httprequest_Spring Webflux_Spring Webclient_Spring Reactive - Fatal编程技术网

Java 为什么webClient不';不做任何http调用?

Java 为什么webClient不';不做任何http调用?,java,httprequest,spring-webflux,spring-webclient,spring-reactive,Java,Httprequest,Spring Webflux,Spring Webclient,Spring Reactive,我有以下代码: List<Mono<MyResponseDTO>> monoList = queue.stream() .map(jobStatusBunch -> webClient .post() .uri("localhost:8080/api/some/url") .bodyValu

我有以下代码:

 List<Mono<MyResponseDTO>> monoList = queue.stream()
                .map(jobStatusBunch -> webClient
                        .post()
                        .uri("localhost:8080/api/some/url")
                        .bodyValue(convertToRequestDto(someBean))
                        .retrieve()
                        .toEntity(String.class)
                        .filter(HttpEntity::hasBody)
                        .map(stringResponseEntity -> {
                            try {
                                return objectMapper.readValue(stringResponseEntity.getBody(), MyResponseDTO.class);
                            } catch (JsonProcessingException e) {
                                log.error("Can't parse", e);
                                return null;
                            }
                        })
                        .doOnNext(myResponseDTO -> {
                            log.info("doOnNext is invoked");
                        })
                ).collect(Collectors.toList());
        //await when all MONOs are completed
        Mono<Void> mono = Flux.fromIterable(monoList).then();
        mono.subscribe(aVoid -> {
            log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        });
我的目标是允许并行执行队列中的所有http请求,并等待所有请求完成。但是,尽管队列不是空的,但实际的http调用不会发生。你能解释一下为什么以及如何修复它吗

更新 谢谢@caco3的建议。我更正了如下代码:

log.info("Start waiting for {}", monoList);
Mono<Void> mono = Flux.fromIterable(monoList)
        .flatMap(Function.identity())
        .then();
log.info("Finished waiting for {}", monoList);

因此,当前代码并不等待所有请求的终止。但我确实需要它。

可能,您的意思是将
通量展平:
通量.fromIterable(monoList).flatMap(Function.identity())。然后()
@caco3是-您是对的。但是doOnNext回调在.subscribeSure之后调用,即使在.subscribeSure之后,工作仍在另一个线程上进行。如果要记录终止,可以使用operator@caco3我的目标是等待请求完成。我想要同步操作。然后你可以在
Mono上
block
log.info("Start waiting for {}", monoList);
Mono<Void> mono = Flux.fromIterable(monoList)
        .flatMap(Function.identity())
        .then();
log.info("Finished waiting for {}", monoList);
2019-11-19 19:17:17.733  INFO 5896 --- [   scheduling-1] c.b.m.service.MyService     : Start waiting for [MonoPeek]
2019-11-19 19:17:25.988  INFO 5896 --- [   scheduling-1] c.b.m.service.MyService     : Finished waiting for [MonoPeek]
2019-11-19 19:17:26.015 TRACE 5896 --- [   scheduling-1] o.s.w.r.f.client.ExchangeFunctions       : [c42c1c2] HTTP POST localhost:8080/api/some/url, headers={}
2019-11-19 19:17:48.230  INFO 5896 --- [tor-http-nio-11] c.b.m.service.MyService     : doOnNext is invoked