Implementing asynchronous SSE
Like the WebSocket, the SSE is a real-time mechanism for sending messages from the server to client applications. However, unlike the WebSocket, it establishes unidirectional communication between the server and client applications.
There are many ways to build server push solutions in Flask, but our applications prefer using the built-in response’s text/event-stream
.
Implementing the message publisher
SSE is a server push solution that requires an input source where it can listen for incoming data or messages in real time and push that data to its client applications. One of the reliable sources that will work with SSE is a message broker, which can store messages from various resources. It can also help the SSE generator function to listen for incoming messages before yielding them to the clients.
In this chapter, our ch05-web
application utilizes Redis as the broker, which our ch05-api
project used for invoking the Celery background...