This project involves developing a client-server script in Python to handle MQTT messages via RabbitMQ. The client script emits MQTT messages every second containing a field "status" with a random value in the range of 0-6. The server processes these messages and stores them in MongoDB. Additionally, the server provides an endpoint to accept start and end times and return the count of each status during the specified time range.
- Implement MQTT messaging via RabbitMQ.
- Emit MQTT messages every second with a "status" field containing a random value between 0 and 6.
- Develop a server script to process incoming MQTT messages.
- Store the processed messages in MongoDB.
- Create an endpoint to accept start and end times.
- Return the count of each status within the specified time range using MongoDB's aggregate pipeline.
- Python 3.8+
- Docker
- Docker Compose
- Clone the Repository
git clone git@github.com:i-shubham01/mqtt.git cd mqtt-rabbitmq-mongodb
- **Build and Run the Docker Containers
docker-compose up --build
- **Install Dependencies
pip install -r requirements.txt
- ** Set Required Envs
MONGO_URI = os.getenv('MONGO_URI', 'mongodb://localhost:27017/') MONGO_DB = os.getenv('MONGO_DB', 'mqtt') RABBITMQ_HOST = os.getenv('RABBITMQ_HOST', 'localhost') RABBITMQ_PORT = os.getenv('RABBITMQ_PORT', '5672')
- ** Start the server
uvicorn main:app --reload --port <port>
- parameter validations
- Response schema
- logging implementation
- Bussiness logic for message processing
- Exception handling
- Middleware implementation