This repository is a POC on how to send notification using Server Sent Events and Pub/Sub.
- Create a virtual environment
conda create --name sse-notification python=3.9
- Activate virtual environment
conda activate sse-notification
- Install python packages
pip install -r requirements
docker-compose up -d backend
docker-compose down
curl -X 'POST' \
'http://localhost:8000/event/temp' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"foo": "bar"}'
Open the browser and paste the following code to the console
const eventSource = new EventSource("http://localhost:8000/stream/temp");
eventSource.addEventListener("update", function(event) {
// Logic to handle status updates
console.log(event)
});
eventSource.addEventListener("end", function(event) {
console.log('Handling end....')
eventSource.close();
});