I am new to Spring-Webflux.
I am running the below sample project in a 2 - core processor. My RESTful api will call to an external api and the external api response is less than 500ms.
When i using jMeter for load testing, can't achieve more than 15 TPS.
Am i missing something or anything wrong with the below design?
How effective it's to override the default Threadpool executor in Webflux project?
Thank you in advance.
Controller.java
----------------
LookupController
{
@Autowired
private LookupService lookupService;
@PostMapping(value = "/findOrder")
public Mono> findOrder(@RequestBody InputBean inputBean) {
return lookupService.findOrder(inputBean)
.map(resp -> ResponseEntity.ok(resp))
.defaultIfEmpty(ResponseEntity.notFound().build());
}
}
Service
---------
@Service
public class LookupService
{
private RestWorker restWorker;
public Mono findOrder(InputBean inputBean)
{
..//Basic Validation
ApiBean apiBean = restWorker.buildApiBean(inputBean);
Mono responseStr = restWorker.callApi(apiBean);
return responseStr.flatMap(resp -> {
//Business Logic
//Process the api response and create the corresponding Controller Response
return Mono.just(controllerResponse);
});
}
}
Helper
---------
@Component
public RestWorker {
private Webclient webClient = null;
@PostConstruct
private void initWorker() {
webClient = WebClient.builder()
.baseUrl(httpUrl)
.defaultHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.defaultHeader(HttpHeaders.ACCEPT, "application/json")
.defaultHeader(HttpHeaders.ACCEPT_CHARSET, "UTF-8")
.build();
}
public ApiBean buildApiBean(InputBean inputBean) {
// Create ApiBean based on the input bean + config values
....
return apiBean;
}
public Mono callApi(ApiBean apiBean) {
Mono responseMonoStr = null;
try {
responseMonoStr = webClient.post()
.uri(url_tibco)
.body(BodyInserters.fromObject(reqDoc))
.exchange()
.timeout(Duration.ofMillis(socketReadTimeout))
.flatMap(clientResponse -> {
System.out.println(Thread.currentThread().getName() + "Status
Code : " + clientResponse.statusCode());
return clientResponse.bodyToMono(String.class);
});
}catch(Exception exception){
return Mono.just("");
}
}
}