Wie blockiere ich () Reaktor -HTTP -Thread, während ich mit Spring Boot WebClient API aufruft?Java

Java-Forum
Anonymous
 Wie blockiere ich () Reaktor -HTTP -Thread, während ich mit Spring Boot WebClient API aufruft?

Post by Anonymous »

Ich schreibe eine generische Methode, um API von Drittanbietern von meinem Mikroservice aufzurufen. < /p>
private R processRequest(String url, Class type, HttpEntity requestEntity, HttpMethod method) {

HttpHeaders httpHeaders = requestEntity.getHeaders();

Mono result = getResult(method, url, httpHeaders, type);
R responseBody = result.block();

return responseBody;
}

private Mono getResult(HttpMethod method, String url, HttpHeaders httpHeaders, Class type) {
return webClient.method(method)
.uri(url)
.accept(MediaType.ALL)
.contentType(MediaType.APPLICATION_JSON)
.headers(headers -> headers.putAll(httpHeaders))
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError,
clientResponse -> Mono.error(new RuntimeException("Client error")))
.onStatus(HttpStatusCode::is5xxServerError,
clientResponse -> Mono.error(new RuntimeException("Server error")))
.bodyToMono(type);
}
< /code>
Aber wenn ich processRequest () -Methode aufrufe, erhalte ich den folgenden Fehler. < /p>
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3
< /code>
Kann jemand bitte helfen, dieses Problem zu lösen. Es ist nicht gut, Blockierungsvorgänge im Reaktivcode

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post