-1

I have been strugling against this for two days now, and finally reach a dead end.

Thing is, I'm handling a request like this:

public Mono<ServerResponse> jsonBodyDemo(ServerRequest request) {  

    request.bodyToMono(DemoDTO.class).log().subscribe(
        d -> System.out.println(d.getName()),
        e -> System.out.println("error"));

    return ServerResponse.ok().body(BodyInserters.fromValue("OK"));
}

And the name is never logged. All I get is:

2020-04-29 14:46:39.210  INFO 20404 --- [ctor-http-nio-3] reactor.Mono.OnErrorResume.1             : onSubscribe(FluxOnErrorResume.ResumeSubscriber)
2020-04-29 14:46:39.210  INFO 20404 --- [ctor-http-nio-3] reactor.Mono.OnErrorResume.1             : request(unbounded)

But the actual onNext never happens

Any suggestion about what I'm missing?

4

1 回答 1

0

您几乎不应该订阅 webflux 应用程序。您的服务是生产者,发起调用的是订阅者(调用客户端)

public Mono<ServerResponse> jsonBodyDemo(ServerRequest request) {  
    return request.bodyToMono(DemoDTO.class)
             .flatMap(dto -> {
                 System.out.println(dto.getName());
                 return ServerResponse.ok().body(BodyInserters.fromValue("OK"));
             });
}

当您订阅时,您打破了链条,将所有内容视为需要连接所有内容的流程。

于 2020-04-29T22:05:01.440 回答