Как заблокировать () поток Reactor Http при вызове стороннего API с использованием веб-клиента загрузки Spring? ⇐ JAVA
Как заблокировать () поток Reactor Http при вызове стороннего API с использованием веб-клиента загрузки Spring?
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
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
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Какой стек HTTP для использования для клиента, требующего HTTP/1.1, HTTP/2 и HTTP/3
Anonymous » » в форуме Android - 0 Ответы
- 63 Просмотры
-
Последнее сообщение Anonymous
-