The goal of this project is to compare WebClient and RestTemplate in a Spring MVC application on Wildfly.
WebClient is part of the WebFlux reacive stack, but it can improve the performance of a classic application, for example a Spring MVC application on Wildfly.
This repository contains two simple application:
- rest-template-vs-web-client: Spring App that exposes two endpoints:
- /resttemplate/samples/{id}: call the service exposed by slow-application using RestTemplate;
- /webclient/samples/{id}: call the service exposed by slow-application using WebClient;
- slow-application: a very simple node application in order to simulate a slow app (response time 2 seconds).
- /samples/:id and return a json like this { id: 1, details : "Exmplae details"};
In order to build and run this project are required:
- Apache Maven;
- JDK 8+;
- Wildfly;
- Node.
An alternative is to run the docker compose:
docker-compose up
You can compare the two modules with Apache Bench:
-
RestTemplate
ab -n 5000 -c 500 http://127.0.0.1:8080/rest-template-vs-web-client/api/resttemplate/samples/7
-
Webclient
ab -n 5000 -c 500 http://127.0.0.1:8080/rest-template-vs-web-client/api/webclient/samples/7