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

Viewed 296

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".

1 Answers

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

Related