Set up complete MQTT broker infrastructure with RabbitMQ and Redis for transit vehicle tracking #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Key Features
.env
fileData Storage Schema
Vehicle data is stored in Redis with the following structure:
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 filesconfig/rabbitmq/enabled_plugins
- Enables MQTT and management pluginsconfig/rabbitmq/rabbitmq.conf
- RabbitMQ MQTT configurationSubscriber Service:
subscriber/Dockerfile
- Python 3.11 containersubscriber/requirements.txt
- Dependencies (paho-mqtt, redis)subscriber/subscriber.py
- Main service with MQTT subscription and Redis storage logicExamples & Testing:
examples/publisher_example.py
- Test MQTT publisher that generates simulated vehicle dataexamples/query_redis.py
- Tool to query and display stored vehicle dataexamples/README.md
- Documentation for example scriptsDocumentation:
README.md
- Comprehensive guide with architecture, setup, configuration, and troubleshootingQUICKSTART.md
- Simplified quick start guide for rapid deploymentUsage
Start the complete system with a single command:
Test with the provided examples:
Access the RabbitMQ management UI at http://localhost:15672 (admin/admin)
Configuration
Customize behavior via environment variables in
.env
:RABBITMQ_USER
/RABBITMQ_PASS
- Authentication credentialsMQTT_TOPIC
- Topic pattern to subscribe to (default:transit/vehicles/#
)REDIS_DB
- Redis database number (default: 0)Technical Details
The system is now ready for production deployment to collect and store real-time transit vehicle tracking data.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.