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.
Related
We have set of services in a vertx cluster. We serve web front end through a API gateway which is one service within the cluster. Client ask a requirement for download some data as a CSV file. It should be transmitted as bellow.
Service A --(Event bus)---> API gateway ---(Web socket)---> Browser
My question is, is it wise to stream such file over event bus from Service A to API gateway? (File may get as large as 100 MB)
You can, but its not designed for it. Will create congestion because the entirety of the file will be kept in memory until transfer is complete. Just set up a http server, communicate the url through a consumer and upload it over http. Then you get all http support as well.
If you don't want a perm http server for it, just start one whenever a request for an upload comes in.
I have separate application for client side which is in ReactJs and NodeJS (Express server) and Web Services in Java application running in tomcat.
My query is which is better approach in terms of making web service call.
One is making direct web service call from ReactJS and get the data.
Other one is calling web service in Express server. Request from client browser will go to Express and Express will make all web services call.
I know one issue in making direct call to web service will be cross domain policy which can be handle by setting configuration in Java server.
Apart from it what should be better approach.
From my experience it ended up better using direct calls from UI application and avoiding intermediate server.
Reason for doing this directly is that our servers ended up with a lot of restrictions based on IP addresses, and all requests have been coming from intermediate server (nodeJS server), so DDOS protection of end server had to have some exceptions (our node server which could be on ACS with dynamic IP addresses so it might be hard to manage).
Also If you want to pass and track end users IP addresses, you need to manage headers on Node server (to be sure you are passing it as it was in original request).
It is way simpler to manage this kind of situation if calls are comming from React app and simply set up CORS on java server.
Also its way easier to debug it on UI app directly, so you will be watching response logs on one place only. Other way around you could end up debugging your node server and UI app.
Hope this helps a bit.
Best way IMO is to create a router in Node js specifically for all your Java webservices and act as a proxy.
Suppose if your url pattern is like http://domain/java-ws/api then all these requests will be routed to your Java service.
If you have an Apache server directing requests to your node JS then configure url pattern proxy using proxy module.
Browsers are blocking CORS requests for a reason. You may get away by setting things on your server.
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.
I am looking for a simplest solution to create a client-server network architecture using Spring 3 framework. The architecture woill have many clients and multiple servers. Each client can connnect to each server. Each client can define a set of services that would have to be generated during runtime by the server.
Communication protocol:
Client says hello to one of 5 servers.
Server gather its local metadata about stored data and send it to client
Client pick some of this info and send the metadata subset to server deciding which data it will need later.
Server basing on the metadata choice, picked by the client, generates dynamically services that will be made available to the client supplying him with data pointed by the requested (step 3) config (eg in form serialized JSON)
Client get the information about generated services and use it for future calls to those services.
The biggest issue is that client doesn't know nothing about server resources to be served until it receives answer and server has no services since it get request from client.
I considered Spring 3:
HTTP Invokers
JMS
Netty (joined with spring)
But as far as I tried the above it's ether hard to provide the dynamic service generation requirement or the amount of code (Netty) is big.
I have rejected SOAP due to its heavy nature.
On the other hand REST does not bring here as far as I know any benefits. It is just a way of serving data and it require some kind of servlet container like Tomcat as it uses HTTP. #Timmmm 's great and simple answer to REST fashion
What I am after:
as simple as possible
dynamic generation of services based on client choice
keep server lightweight i.e. no additional server instance (it would be nice to eliminate tomcat; but ts not crucial)
spring based
What technology would you recommend?
It is quiet hard to accomplish this task with the requirement of configuration based service generation during runtime.
I do NOT want to base on properties files, services must be generated on the fly based on the client request.
Thank you in advance for answers and tips.
I would look at RESTful architecture. Some of its principals is what you are after, including discovery.
Spring provides easy integration with REST.
I have a Java web service that returns a large amount of data. Is there a standard way to stream a response rather than trying to return a huge chunk of data at once?
This problem is analogous to the older problem with bringing back large RSS feeds. You can do it by parameterizing the request: http://host/myservice?start=0&count=100, or by including next/prev urls in the response itself.
The latter approach has a lot of advantages. I'll search for a link that describes it and post it here if I find one.
I would look into a comet like approach:
From WIKI:
Comet is a web application model in which a long-held HTTP request
allows a web server to push data to a browser, without the browser
explicitly requesting it.
Basically, rather than sending the large data all at once, allow your web server to push data at its own pace and according to your needs.
Webservice might not be a good method for data transfer.
If I were you, I would like to setup another service like FTP or SFTP.
The server puts the data to the specific path of the FTP server and sends the path information to the client through the webservice response.