Java Spring: real-time status update for client via REST API
I am developing a web application in Java Spring where I want the user to be able to load a CSV file from the front-end and then see the progress of the import process in real time and after import it should be able to search for individual records from the imported data.
The import process would be to actually download the file (send it via a REST API POST request) and then read it and save its contents to the database so that the user can search that data.
How can I show the progress of this process in real time? I found a tutorial for jQuery that shows the progress of the amount of data uploaded / transferred, but since most of the work is done while processing the uploaded file, I thought I needed a solution where, before processing the line, I find out the amount of lines in the file, and then the user could see a live message like:
Processed lines: 1 in 10000
It may update / change gradually, but as one line is processed quite quickly, displaying each number of lines processed is not that important.
Anyway, the question is what is the simplest way to send these messages from the Spring REST API to the client?
source to share
I found a solution myself and used websockets for this.
I used this approach from Spring documentation:
https://spring.io/guides/gs/messaging-stomp-websocket/
This might help when sending messages for each processed line to the front end receiver (after the websocket topic / connection is started), but I used a different approach to import the data, I used batch insert, so it is not available to me, but networked sockets are capable of doing this.
source to share