Skip to content

The microservice emits time-series events at regular intervals. These events could represent metrics like temperature, CPU usage, or financial stock data.

License

Notifications You must be signed in to change notification settings

IamMashed/timeSeriesEventEmitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.


Key Features

  1. Real-Time Streaming:

    • The /stream endpoint streams time-series events continuously using Server-Sent Events (SSE).
  2. Historical Data Retrieval:

    • The /history endpoint retrieves the last N events stored in the PostgreSQL database.
  3. Customizable Event Interval:

    • The /set_interval endpoint allows users to configure the interval for time-series event generation.
  4. Fully Dockerized:

    • Both the Flask application and PostgreSQL database are containerized for easy deployment using Docker.

Getting Started

Prerequisites

  • Docker and Docker Compose must be installed on your machine.
  • Python 3+ is recommended if running locally without Docker.

Installation

  1. Clone the repository:
git clone https://github.com/IamMashed/timeSeriesEventEmitter.git
cd timeSeriesEventEmitter

Usage

Dockerized Setup

  1. Start the application:
docker-compose up --build

Database Initialization (First-Time Setup)

  1. Start an interactive shell inside the Flask application container:
docker exec -it flask_app flask shell
  1. Initialize the database:
from app import db
db.create_all()
  1. Exit the shell:
exit

Core Endpoints

  1. /stream:
    • Streams time-series events. Access it via:
curl http://localhost:5000/stream
  1. /history:
    • Retrieves the last N events from the database. Example usage:
curl http://localhost:5000/history?count=10
  1. /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}'

Project Structure

  • Flask app: Manages the SSE streaming and API logic.
  • PostgreSQL database: Stores historical events.
  • Docker Compose: Orchestrates the Flask app and PostgreSQL as containers.

Contributing

Feel free to fork the repository, report issues, or propose changes via pull requests.

About

The microservice emits time-series events at regular intervals. These events could represent metrics like temperature, CPU usage, or financial stock data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published