Skip to content

Journey

why not….

  • Home
  • 2020
  • December
  • 5
  • Server Sent Events

Server Sent Events

Posted on December 5, 2020December 5, 2020 By dion No Comments on Server Sent Events
reactive, spring

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://mkyong.com/spring-boot/spring-boot-webflux-server-sent-events-example/

https://www.youtube.com/watch?v=T_JZzdPCkOU&ab_channel=JavaGrowth – useful video

Post navigation

❮ Previous Post: Git reset without committing
Next Post: CSS Selectors ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2025 Journey.

Theme: Oceanly by ScriptsTown