mcool
mcool

Reputation: 785

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

Upvotes: 3

Views: 1363

Answers (1)

Hopey One
Hopey One

Reputation: 1816

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

Upvotes: 1

Related Questions