Как заблокировать () поток Reactor Http при вызове стороннего API с использованием веб-клиента загрузки Spring?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Как заблокировать () поток Reactor Http при вызове стороннего API с использованием веб-клиента загрузки Spring?

Сообщение Anonymous »


I am writing a generic method to call third party API from my micro-service.

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); } But, when I am calling processRequest() method, I am getting the below error.

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-3 Can anyone please help to solve this issue.

Tech stack : Java : 17 spring-boot-starter-parent : 3.1.1 spring-boot-starter-webflux : 3.1.1

P.S. I need a blocking call and I am aware that it is not good to use blocking operations in reactive code


Источник: https://stackoverflow.com/questions/780 ... -spring-bo
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»