问题描述
我有一个 Client1,它调用 Client2,它调用一个 Producer 来获取数据。 Client2 订阅了 Producer 并毫无问题地收到了 Mono。 但是 Client2 在 Subscribe 完成之前返回并且 Client1 没有得到有效的结果。
Client1 不是 Spring Boot, Client2 使用 webflux 和 spring boot
如何让 Client1 接收有效值。
======================
客户端 1 调用 -->
Mono<ClientResponse> method1(Request someRequest){
WebClient webClient = buildWebClient(arg1);
Mono<ClientResponse> webClientResponse = webClient.post()
.uri("url")
.accept(MediaType.TEXT_XML)
.contentType(MediaType.TEXT_XML)
.header("someheader")
.body(BodyInserters.fromValue(request))
.exchange();
webClientResponse.subscribe(clientResponse -> {
if(clientResponse.statusCode().value() == 200 && clientResponse.statusCode().getReasonPhrase().equals("OK")) {
HttpHeaders headers = clientResponse.headers().asHttpHeaders();
Mono<String> valueMono = clientResponse.bodyToMono(String.class);
valueMono.subscribe(value -> {
//got the value here
});
}//ok
});
return null;//<--here return before subscribe has finished
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)