Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 2, 2025

Overview

This PR implements a complete MQTT broker infrastructure for collecting real-time transit vehicle tracking and telemetry data. The system uses RabbitMQ as the MQTT broker and Redis as an in-memory database for fast data retrieval, all containerized with Docker for easy deployment.

Architecture

The implementation consists of three main containerized services:

Transit Vehicles → MQTT (1883) → RabbitMQ → Subscriber Service → Redis (6379)
  1. RabbitMQ MQTT Broker: Receives MQTT messages from transit vehicles on port 1883, with a management UI on port 15672
  2. Redis Database: Provides in-memory storage with sub-millisecond access times on port 6379
  3. Python Subscriber Service: Bridges MQTT to Redis, automatically storing incoming vehicle data with TTL and timeline indexing

Key Features

  • Docker-based deployment: All services orchestrated with Docker Compose for consistent deployment
  • Health checks and dependencies: Services start in proper order with automatic health monitoring
  • Automatic reconnection: Built-in retry logic for resilient service connections
  • Data expiration: 1-hour TTL on vehicle records to manage memory usage
  • Timeline indexing: Sorted set for efficient time-based data queries
  • Environment-based configuration: Easy customization via .env file
  • Comprehensive logging: Structured logging throughout for debugging and monitoring

Data Storage Schema

Vehicle data is stored in Redis with the following structure:

Key: "vehicle:{vehicle_id}"
Value: {
  "vehicle_id": "1234",
  "lat": 40.7128,
  "lon": -74.0060,
  "speed": 25,
  "heading": 180,
  "_timestamp": "2024-01-15T10:30:00.123456",
  "_topic": "transit/vehicles/bus/1234"
}
TTL: 3600 seconds

Additionally, a timeline index (vehicles:timeline) tracks all vehicles as a sorted set by timestamp for efficient time-based queries.

Files Added

Infrastructure & Configuration:

  • docker-compose.yml - Orchestrates RabbitMQ, Redis, and subscriber services
  • .env.example - Environment variable template
  • .gitignore - Standard patterns for Python, Docker, and IDE files
  • config/rabbitmq/enabled_plugins - Enables MQTT and management plugins
  • config/rabbitmq/rabbitmq.conf - RabbitMQ MQTT configuration

Subscriber Service:

  • subscriber/Dockerfile - Python 3.11 container
  • subscriber/requirements.txt - Dependencies (paho-mqtt, redis)
  • subscriber/subscriber.py - Main service with MQTT subscription and Redis storage logic

Examples & Testing:

  • examples/publisher_example.py - Test MQTT publisher that generates simulated vehicle data
  • examples/query_redis.py - Tool to query and display stored vehicle data
  • examples/README.md - Documentation for example scripts

Documentation:

  • README.md - Comprehensive guide with architecture, setup, configuration, and troubleshooting
  • QUICKSTART.md - Simplified quick start guide for rapid deployment

Usage

Start the complete system with a single command:

docker-compose up -d

Test with the provided examples:

# Publish test vehicle data
python examples/publisher_example.py

# Query stored data
python examples/query_redis.py

Access the RabbitMQ management UI at http://localhost:15672 (admin/admin)

Configuration

Customize behavior via environment variables in .env:

  • RABBITMQ_USER / RABBITMQ_PASS - Authentication credentials
  • MQTT_TOPIC - Topic pattern to subscribe to (default: transit/vehicles/#)
  • REDIS_DB - Redis database number (default: 0)

Technical Details

  • RabbitMQ: Version 3 with management plugin, MQTT plugin enabled on port 1883
  • Redis: Version 7 Alpine with AOF persistence enabled
  • Python Subscriber: Python 3.11 with paho-mqtt 1.6.1 and redis 5.0.1
  • Total Implementation: 847 lines of code and documentation across 13 files

The system is now ready for production deployment to collect and store real-time transit vehicle tracking data.

Original prompt

Please set up a repository for developing a MQTT broker using RabbitMQ within a Docker container. This broker will collect real-time transit vehicles tracking and telemetry data and store it in an external in-memory database (Redis) for quick data retrieval.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title Please set up a repository for developing a MQTT broker using RabbitMQ within a Docker container. This broker will collect real-time transit vehicles tracking and telemetry data and store it in an external in-memory database (Redis) for quick data retr... Set up complete MQTT broker infrastructure with RabbitMQ and Redis for transit vehicle tracking Oct 2, 2025
@Copilot Copilot AI requested a review from fabianabarca October 2, 2025 20:55
Copilot finished work on behalf of fabianabarca October 2, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants