我不太清楚如何正确翻译以下对Spring WebFlux WebClient的调用。
userIds是一个列表,我可以使用以下语法调用服务,但我无法在Spring WebFlux WebClient中使其正常工作。如果您知道如何操作,请帮助我。
String url = "http://profile.service.com/v1/profiles/bulk";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<List<MiniProfile>> responseEntity;
try {
responseEntity = restTemplate.exchange(url, HttpMethod.POST, new
HttpEntity(userIds, headers), new
ParameterizedTypeReference<List<MiniProfile>>() {});
} catch (RestClientException e) {
responseEntity = new ResponseEntity<List<MiniProfile>>(HttpStatus.OK);
}
return responseEntity.getBody();
这是我将其翻译为Webflux WebClient的方式:
Flux<String> flux = Flux.fromIterable(userIds);
return readWebClient.post().uri("/v1/profiles/bulk")
.body(BodyInserters.fromPublisher(flux, String.class))
.retrieve().bodyToFlux(MiniProfile.class);
application.properties
文件中设置日志级别,例如:logging.level.reactor.ipc.netty.channel.ContextHandler=debug
和logging.level.reactor.ipc.netty.http.client.HttpClient=debug
。 - Brian Clozel