REST api for processing parallel HTTP GET requests - spring

My question might be quite basic.
I have a Spring MVC (Spring Boot) REST api, and multiple Spark workers that send parallel HTTP GET requests to this REST api (e.g. 4 workers on different nodes -> 4 parallel HTTP requests). I want my REST api be able to process these requests in parallel.
How can I do it? Should I use callbacks and DeferredResult inside my REST api? Any example would be really helpful.

Take a look at AsyncRestTemplate.

AsyncRestTemplate is deprecated. Take a look at WebClient instead.

Related

How to consume REST API and SOAP endpoint using one rest API?

We have an application that uses both rest API and soap API. At a time we use either of them, but the requirement is to change it when needed. So, the question is there a way to use a single API that can handle REST and SOAP requests, so that we can use either of them depending on our condition in spring boot?
I have tried to call using single rest API. My expectation is to find a mechanism that can handle both soap and rest requests.

Making REST calls in parallel in Apache Camel

I am using Apache Camel Java DSL in a Spring Boot project. In the Camel route, I am calling two rest services sequentially, combining their outputs and sending to another application from the Camel route. Now we are trying to call the REST services in parallel. We were able to call the REST services in parallel by implementing the following steps:
In the route, first storing the two URLs of the two REST services in a list within an exchange.
Applying Splitter EIP and parallelProcessing() on that EIP to call two differrent Camel routes in parallel which calls the REST service.
Unmarshalling the response of the services from JSON to POJO
The problem is if I use an aggregationStrategy to aggregate the responses, how canI handlethe scenarion when the two REST services will return two different objects after unmarshalling the response? Also please suggest any better approach of calling the REST services in parallel and consolidating their responses.

SpringBoot FeignClient vs WebClient

I want to consume a couple of rest services. Before I have used RestTemplate, but now I want to know What is main diffrences of SpringBoot FeignClient and WebClient?
when they should be used?
To be able to answer “when” one needs to understand the capabilities of each.
Spring WebClient is a non-blocking reactive client to make HTTP requests. Hence if you intend to use Spring Reactive Stream API to stream data asynchronously then this is the way to go. Think event-driven architecture. WebClient is part of the Spring WebFlux library.
[Feign]3 is a declarative REST library that uses annotations based architecture with thread-per-request model. This means that the thread will block until the feign client receives the response. The problem with the blocking code is it must wait until the consuming thread completes, hence think memory and CPU cycles.
So use Spring WebClient when needing non-blocking HTTP requests otherwise Feign due to simple usage model.
(Note: There is no reason as to why one cannot use WebClient for blocking operations but Feign is more mature and it’s annotation based model makes it easier)
The main difference is that WebClient supports Reactive calls.
You can achieve that with 3rd party feign clients like https://github.com/Playtika/feign-reactive but basically for a reactive way you should consider using WebClient with some neat async connector like Jetty. On the other hand, If you want a blocking way with minimal hassle then Feign could be your best choice.
WebClient is a non-blocking reactive.
Feign is blocking.

Rate limit web client

I am building a microservice using spring webflux and netty. Internally I use web client to make rest api calls. How can I control rate at which I can call rest api via webclient? I guess backnpressure is only for a single request/reply and does not work across multiple request to my microservice. Amy pointers will be appreciated.Thanks.
Resilience4j has support for non-blocking rate limiting with Reactor.
See: https://resilience4j.readme.io/docs/examples-1#decorate-mono-or-flux-with-a-ratelimiter

Calling REST APIs in Spring and multithreading

My Spring app will call couple of external APIs with each get request.
I understand that Spring can handle a large number of calls at a time.
But here I read about multithreading
REST Api with Multithreading for handling Files in Spring Boot
So I was wondering:
1. Does Spring implement multithreading out of the box?
2. Would using async http calls to the external APIs increase the performance, load tolerance of my App/RESTAPI?
thanks

Resources