Real-time energy meter data streaming using Kafka, Go backend, and WebSockets.
- Go 1.18 or later
- Docker and Docker Compose
- Python 3.7 or later
- A terminal/command prompt
# Clone the repository (if not already cloned)
git clone git@github.com:Prypiatos/E3.git
cd E3# Copy the test environment file
cp .env-test .env
# Or manually create .env in the project root with these variables:
# BOOTSTRAP_SERVERS=localhost:9092
# TOPIC_NAME=energy-readings
# CONSUMER_GROUP_ID=energy-consumer-groupcd apps/backend
docker compose up -dThis starts Kafka broker on localhost:9092
Wait 10-15 seconds for Kafka to fully initialize before proceeding.
In a new terminal:
cd apps/backend
# Install Go dependencies
go mod tidy
# Build the backend server
go build -o build/main main.go
# Run the backend server
./build/mainThe server will start on http://localhost:8080 and begin listening for Kafka messages.
cd apps/backend
# Build the producer
go build -o build/producer cmd/producer.go
# Run the producer to send test data
./build/producerThe producer will send energy meter readings to Kafka every second.
cd apps/frontend
# Start an HTTP server
python -m http.server 8000The frontend will be available at http://localhost:8000.
- Open your browser and go to
http://localhost:8000 - Open Developer Tools (F12 or Ctrl+Shift+I)
- Go to the Console tab
- You should see energy readings streaming in real-time as JSON objects
Press Ctrl+C in the terminals running the backend and producer.
Press Ctrl+C in the terminal running the HTTP server.
cd apps/backend
docker compose down- Backend (
apps/backend/main.go): WebSocket server consuming from Kafka - Producer (
apps/backend/cmd/json_producer.go): Generates test energy meter data - Frontend (
apps/frontend/index.html): Connects to backend WebSocket and displays data - Kafka: Message broker for energy readings
- Backend WebSocket:
localhost:8080/ws - Frontend HTTP:
localhost:8000 - Kafka Broker:
localhost:9092