Can a Spring Boot application make HTTP request to itself? - java

We are deploying Spring Boot app to the Kubernetes.
When the firs user requests comes it takes more than 10s to response.
Subsequent requests take 200ms.
I have created a warmup procedure to run the key services in #PostConstruct. I reduces the time to process the first query to 4s.
So I wanted to simulate this first call. I know that Kubernetes rediness probe can make a POST request, but I need authorization and other things. Can I make a real HTTP call to the controller from the app itself?

Sure, you can always make an HTTP client to localhost
The solution isnt specific to k8s or Spring or Java, but any web server
You could also try making your readiness probe just the tcp port or some internal script

try RestTemplate , you can consume any web service

Related

Restream files from another server to client springboot

I have 2 services - Ingress (input node) and Storage.
Client send requests on Ingress to get some data (large files).
Ingress send request to Storage to get data that Client needs.
Maybe, somebody can tell what I can use to restream response from Storage to Client without OutOfMemory issues.
Now I've implemented it as saving result in file on Ingress, rereading it and sending as response to Client. But it works really slow, of course.
Thank you.
Spring Cloud Gateway (more documentation here) can help. It's primary purpose seems to be as a configuration-driven gateway, but it can be embedded into an application to serve just certain endpoints; so you may be able to configure it in your "Ingress" service to route certain requests to your Storage service.
If that doesn't work (or, as was in my case, it's too much work), you can use some specific classes from Spring Cloud Gateway in your own service. Specifically, I've used the ProxyExchange class to proxy calls to another service and stream the results back to the original caller.

need solution for 504 error for REST API hosted in cloud

When I tested REST endpoint locally it is working fine but when we host application in cloud other APIS are working fine only one API is giving 504 error. Please give me possible solution. REST API is implemented using spring boot.
Thanks.
504 Gateway Time-out issue is generally thrown by a proxy server that means the server is closing connection.
I will need more details like
Does the API that you are calling do a long-running task that is taking longer than what proxy time out is set to?
Can the task be optimized in any way? - If you cannot optimize the task itself use an Async function or increase the proxy timeout in the server.

How to work with asynchronous process from external client?

please give me some advice about the best pattern of the task solution. My task is this:
User makes a request to the Camunda processor through own rest
controller
BPMN schema on a backend side consists of a chain of
several asynchronous services
Data will be ready for response to
the User only when one final service on BPMN makes it.
Every chain works not greater than 10-15 secs. And users sessions count is less than 500 an hour.
How to organize the work of the rest controller? Is it acceptable to force controller waiting of result in the same call? Where a bottleneck?
Can you use some server push technology? If it were just a couple of seconds, I'd say go for waiting in the rest controller.
Being 15 seconds and thinking about scalability, I'd say to follow some kind of asynchronous pattern with the client to.
Client sends a request to do something
The controller delegates the work to some external process and returns to the client ok
The process ends and a response is ready.
If the other side is a browser, use some kind of server push technology to notify it. If it is an application use some kind of rpc, polling or any other inter process mechanism to communicate.
Note that depending on the hosting technology, there are different limits on concurrent connections. Check Spring Boot - Limit on number of connections created for tomcat.

Query an API which blocks CORS

I have an app which needs to query an API which blocks cross-origin requests. Right now, my approach is to query my own API, which then queries the 3rd party API, and then relay the results to frontend. So basically I have set-up proxy endpoints.
This results in extra load on my server which I want to avoid. Is there a way I could do this directly from my frontend code and not have proxy endpoints in backend?
For example, say the following endpoint:
https://fantasy.premierleague.com/drf/bootstrap-dynamic
If you go directly hit the browser with it, it runs fine. But when I use say Angular 2 http to fetch response from it, it is blocked.
Is there a way I could do this directly from my frontend code and not have proxy endpoints in backend?
No. That is the point of CORS being disabled. If you cannot control the server to either disable CORS or allow it for the origin server where your app is running, then you must use a proxy, either by setting up a proxy when serving vi node or by configuring apache/nginx accordingly.

Issue with Configuring Zuul For Reverse Proxy just for serving content

I have embedded the Zuul Proxy into a Spring Boot Application where I use the PreFilter to authenticate request and forward to another Spring Boot Service, which serves content on the basis of timestamp. The content service varies the data size based on the timestamp sent by the client.
Couple of issues being faced:
The Zuul is slowing down the service significantly. When I did performance testing for 25 Hits per sec using zuul in the front, the It gave 4 TPS. However when I removed the zuul as the layer and directly hit the content service with the same scenario I got 32 TPS, which is a huge difference.
Looking at the Ribbon Client it looks to me that it is Using RestTemplate and receiving the content and again returning to the client.
The issue in this approach is that if the content is already served as Compressed, Ribbon is uncompressing and and sending it as compressed back to the client which is a overhead.
I did not find any configuration on Zuul to work purely as a Reverse proxy where in apart from applying filter it should stream the content as is from the forwarding service rather than storing and then returning to the client.
Could anyone help here if they know how to configure Zuul in this scenario?
Due to this performance issue I'm forced to take the authentication layer within content service in order to achieve the best performance.

Categories

Resources