This project demonstrates a simple notification system that utilizes RabbitMQ for message queuing and Mongoengine for object-document mapping to MongoDB. The system simulates sending email and SMS notifications to contacts stored in a database.
producer.py: Script that generates fake contact data and queues messages in RabbitMQ for sending notifications.consumer_email.py: Script that listens for email notification requests and processes them.consumer_sms.py: Script that listens for SMS notification requests and processes them.models.py: Defines theContactdocument schema for Mongoengine.
- Python 3
- RabbitMQ
- MongoDB
- Pika (RabbitMQ Python client)
- Mongoengine
- Faker (for generating fake data)
-
Ensure you have Python 3 installed on your system.
-
Install RabbitMQ and MongoDB and make sure they are running.
-
Install the required Python packages:
pip install pika mongoengine faker
- Ensure RabbitMQ and MongoDB services are up and running.
- No additional configuration is needed unless your RabbitMQ or MongoDB instance requires specific connection parameters. If so, update the connection details in the scripts accordingly.
- Run
producer.pyto generate fake contacts and queue notification messages.python producer.py
- Run
consumer_email.pyin a separate terminal to start listening for email notifications.python consumer_email.py
- Run
consumer_sms.pyin another terminal to start listening for SMS notifications.python consumer_sms.py
producer.pycreates contacts with fake data including full name, email, and phone number, then it decides whether an email or an SMS should be sent based on a random boolean value. The contact's MongoDB ObjectID is then placed into either theemail_queueorsms_queuein RabbitMQ.consumer_email.pyandconsumer_sms.pylisten to their respective queues. When they receive a message, they simulate sending an email or SMS by printing a statement to the console (this is where integration with actual email/SMS sending service would occur). After 'sending' the message, they update theis_contactedfield of the correspondingContactin MongoDB toTrue.