我有一个client1,它调用client2,client2调用数据生产者。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
}
}
暂无答案!
目前还没有任何答案,快来回答吧!