Complete system of two microservices for sensor simulation and real-time data analysis:
- Rust Sensor Simulator - simulates sensors and sends data to RabbitMQ
- Python Analytics Engine - analyzes data in real-time
βββββββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββ
β Rust Sensor βββββΆβ RabbitMQ βββββΆβ Python Analytics β
β Simulator β β Message β β Engine β
β β’ Temperature β β Queue β β β’ Rolling Window β
β β’ Humidity β β β β β’ Statistics β
β β’ Pressure β β β β β’ JSON Export β
β β’ Async timers β β β β β’ CLI Interface β
βββββββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββββββ
- Rust
- Python 3.11+
- Docker (optional)
# Start entire system (in background)
docker compose up -d
# Or start with real-time logs
docker compose up
# View logs for individual services
docker compose logs -f sensor-simulator
docker compose logs -f analytics-engine
# Stop the system
docker compose down
# Rebuild after code changes
docker compose up --buildImportant: Analytics Engine runs in interactive mode. To interact with CLI use:
docker exec -it analytics-engine python cli.pydocker run -d --hostname my-rabbit --name rabbitmq \
-p 5672:5672 -p 15672:15672 \
rabbitmq:3-managementManagement UI: http://localhost:15672
Login: guest / guest
# Build and run sensor simulator
cargo build
cargo run# Install dependencies
cd analytics
pip install -r requirements.txt
# Run analytics
python cli.py- β Simulation of 3 sensor types (Temperature, Humidity, Pressure)
- β Different sampling intervals for each sensor
- β Realistic data (sine wave + noise)
- β Asynchronous programming with Tokio
- β Internal channels for separating generation and publishing
- β Retry logic and error handling
- β Detailed logging
- β Real-time data consumption from RabbitMQ
- β Rolling window (last 10 values)
- β Mean and standard deviation calculation
- β CLI with sensor type filtering
- β Statistics export to JSON
- β Retry logic and graceful error handling
- β Monitoring and logging
- β Docker containerization
{
"sensor_id": "123e4567-e89b-12d3-a456-426614174000",
"sensor_type": "Temperature",
"timestamp": 1716581298,
"value": 24.73
}When running analytics, available commands:
s- show current statisticse- export statistics to JSONf Temperature- filter by sensor typec- clear filterq- quit
cargo testcd analytics
python test_analytics.pysensors/
βββ src/ # Rust Sensor Simulator
β βββ main.rs # Entry point and orchestrator
β βββ sensor.rs # Sensor simulation logic
β βββ publisher.rs # RabbitMQ connection and publishing
β βββ models.rs # Data models
βββ analytics/ # Python Analytics Engine
β βββ models.py # Data models
β βββ analytics_engine.py # Main analytics logic
β βββ cli.py # CLI interface
β βββ test_analytics.py # Tests
β βββ Dockerfile # Docker image
β βββ requirements.txt # Python dependencies
βββ docker-compose.yml # Configuration for entire system
βββ README.md # Documentation
π₯ Temperature | ID: a1b2c3d4... | Value: 24.73 | Average: 24.12 | Std Dev: 1.45 | Window: 10/10 | Total messages: 150
π₯ Humidity | ID: e5f6g7h8... | Value: 62.45 | Average: 63.21 | Std Dev: 3.12 | Window: 10/10 | Total messages: 145
π₯ Pressure | ID: i9j0k1l2... | Value: 1013.25 | Average: 1012.87 | Std Dev: 2.73 | Window: 10/10 | Total messages: 140
π‘οΈ Sensor Analytics CLI
Available commands:
s - Show current statistics
e - Export statistics to JSON
f <sensor_type> - Set filter (Temperature/Humidity/Pressure)
c - Clear filter
q - Quit
> s
π Current Statistics:
Temperature: avg=24.12, count=150, window=10/10
Humidity: avg=63.21, count=145, window=10/10
Pressure: avg=1012.87, count=140, window=10/10
> f Temperature
β
Filter set for: Temperature
> e
β
Statistics exported to: exports/sensor_stats_20250526_105230.json
# Status of all containers
docker compose ps
# Check tests are working
docker exec analytics-engine python test_analytics.py
# Interactive work with Analytics CLI
docker exec -it analytics-engine python cli.py# View logs in real-time
docker compose logs -f
# View RabbitMQ Management UI
# Open http://localhost:15672 (guest/guest)
# Check message queues
docker exec rabbitmq rabbitmqctl list_queues# Connect to container for debugging
docker exec -it analytics-engine bash
docker exec -it sensor-simulator bash
# View exported files content
docker exec analytics-engine ls -la exports/