Automatic updates displayed in client from the server
Basically SSE works by the client opening a long lived connection to a particular endpoint. Unlike websockets, it is uni-directional – meaning that only the server pushes events, the client simply listens. Once a new event is pushed, it can be displayed on the UI
Emitter is a class variable in this example. the client will connect to /connect. Once it does, we will return an instance of emitter which is an event stream.
When the user goes to /dispatch, we can send an event to that emitter.
The client is notified automatically. For example, if i visit /dispatch 3 times, my /connect endpoint will look like this
Note: this is is a good way of notifying clients on demand. If you need a way of continuously spitting out data, consider using webflux for this. Think of a scenario where you are always gathering data such as metrics for cpu/ram and then display it as a stream for your UI to display
https://www.youtube.com/watch?v=T_JZzdPCkOU&ab_channel=JavaGrowth – useful video