I started working on spring-webflux, and unfortunately, my application stuck for an indefinite time.
I have two applications one is reactive and another one is non-reactive.
Application A (NonReactive) makes requests to Application B (Reactive) using WebClient.
Client-Side -
RequestDTO request = new RequestDTO();
Mono<ResponseDTO> monoResponse = webClient.post()
.uri("uri")
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromObject(request ))
.retrieve()
.bodyToMono(ResponseDTO.class)
.timeout(Duration.ofMillis(timeout))
.retryWhen(Retry.any()
.exponentialBackoffWithJitter(Duration.ofMillis(20), Duration.ofMillis(300))
.retryMax(numOfRetries)
.doOnRetry(s -> LOGGER.info("Retrying due to " + s)))
.onErrorResume(e -> Mono.error(new RuntimeException(e)))
.switchIfEmpty(Mono.error(new RuntimeException("Invalid response: " + request)));
monoResponse.subscribe(response -> {
String responseText = null;
try {
responseText = objectMapper.writeValueAsString(response);
} catch (JsonProcessingException e) {
log.error("Error while parsing", e);
}
}, e -> {
log.error("Exception",e);
});
Server Side -
@PostMapping(value = "/process")
public Mono<ResponseEntity<ResponseDTO>> process(@RequestBody RequestDTO request,
ServerHttpRequest serverHttpRequest) {
return Mono.just(ResponseEntity.ok(reactiveService.process(request)));
}
Dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceencoding>UTF-8</project.build.sourceencoding>
<project.reporting.outputencoding>UTF-8</project.reporting.outputencoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor.addons</groupId>
<artifactId>reactor-extra</artifactId>
<version>3.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
I tried looking into the CPU usages, thread dump I was unable to see anything and cpu usage was only 7%.
Could someone please suggest what area should I look for.