Server-Sent Events (SSE)

It is not a new technique. However, it is a technique when we want to have a unidirectional flow of data. Let’s consider a scenario where we have a client-server architecture. The client initiates a request to the server, e.g., fetching messages with a function called getMessages(). The server responds with various messages over time within that particular stream. So, we are creating a channel from the client to the server, and the server responds within that particular channel. Once the client has received all the data it needs, it can close the connection.

Use Cases Server-Sent Events

  • Live Stream: Websites or applications that provide live stream. Examples include, watching a live stream which could be a cricket match e.g.: IPL, YouTube streaming/videos, blogging live blogs, and conferences.
  • Show client progress: Application can provide users with real time updates on the status on the client side. Examples include, file upload, form submissions, real time analytics, etc.
  • Logging: Used in monitoring, handling events on the server side, capturing errors and exceptions that occurs, etc.

Server – Sent Events in Spring

When we design web applications, we generally have a client and a server model, where the client is always the initiator of the transaction or a request to the server. The server responds to these requests. However, in certain scenarios, there arises a need for the server to respond much more frequently or give additional information to the client. This requirement leads us to techniques such as long polling, WebSockets, and Server-Sent Events (SSE).

In this article, we are going to look at Server-Sent Events (SSE) using Spring Boot and how we can implement them.

Similar Reads

Server-Sent Events (SSE)

It is not a new technique. However, it is a technique when we want to have a unidirectional flow of data. Let’s consider a scenario where we have a client-server architecture. The client initiates a request to the server, e.g., fetching messages with a function called getMessages(). The server responds with various messages over time within that particular stream. So, we are creating a channel from the client to the server, and the server responds within that particular channel. Once the client has received all the data it needs, it can close the connection....

Implementation of Server-Sent Events Using Spring Boot

Below is the step-by-step implementation of Server-Sent Events in Spring....

Contact Us