A Server-Sent Events (SSE) based time-series streaming application with PostgreSQL integration. This project allows for real-time event streaming, historical data retrieval, and configurable intervals for event generation, all wrapped in a Dockerized setup.
-
Real-Time Streaming:
- The
/stream
endpoint streams time-series events continuously using Server-Sent Events (SSE).
- The
-
Historical Data Retrieval:
- The
/history
endpoint retrieves the last N events stored in the PostgreSQL database.
- The
-
Customizable Event Interval:
- The
/set_interval
endpoint allows users to configure the interval for time-series event generation.
- The
-
Fully Dockerized:
- Both the Flask application and PostgreSQL database are containerized for easy deployment using Docker.
- Docker and Docker Compose must be installed on your machine.
- Python 3+ is recommended if running locally without Docker.
- Clone the repository:
git clone https://github.com/IamMashed/timeSeriesEventEmitter.git
cd timeSeriesEventEmitter
- Start the application:
docker-compose up --build
- Start an interactive shell inside the Flask application container:
docker exec -it flask_app flask shell
- Initialize the database:
from app import db
db.create_all()
- Exit the shell:
exit
/stream
:- Streams time-series events. Access it via:
curl http://localhost:5000/stream
/history
:- Retrieves the last N events from the database. Example usage:
curl http://localhost:5000/history?count=10
/set_interval
:- Changes the interval for time-series event generation. Example usage:
curl -X POST http://localhost:5000/set_interval -H "Content-Type: application/json" -d '{"interval": 1}'
- Flask app: Manages the SSE streaming and API logic.
- PostgreSQL database: Stores historical events.
- Docker Compose: Orchestrates the Flask app and PostgreSQL as containers.
Feel free to fork the repository, report issues, or propose changes via pull requests.