Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send data from Spring Boot to React front-end without the use of a Controller?

If I have an endpoint, that when hit calls a function that has a CompleteabeFuture.runAsync() call, how can I send this data back to the front end. Here is an example of asyncfunction similar to mine (just simpler):

CompletableFuture.runAsync(() -> {
    int count = 0;
    if(test.getNumberComplete() > count){
        count = test.getNumberComplete();
        logger.info("{}/{} complete so far", count, test.getNumberComplete());
    }
}

Basically, this is running in the background after the Controller has already returned ResponseEntity. So my question is, how can I return the data that is being logged in logger.info() to my front-end. Is this possible at all since the Controller has already returned? My end goal is to show these results in the top corner of the website's screen, something like "1/3 complete so far".

like image 632
mcool Avatar asked Jan 24 '26 02:01

mcool


1 Answers

You could use websockets. There's a simple example here that uses STOMP to pass messages back and forth.

like image 176
Hopey One Avatar answered Jan 26 '26 16:01

Hopey One



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!