This project demonstrates how to set up and use RabbitMQ with Python. It includes examples of how to connect to RabbitMQ, publish messages to a queue, and consume messages from a queue. The project also uses Docker to manage RabbitMQ in a containerized environment.
To run this project, you will need the following:
- Python 3.8+
- Docker
- Docker Compose
- RabbitMQ
-
Create the virtual environment:
python -m venv .venv
-
Activate the virtual environment:
-
On Windows:
.venv\Scripts\activate
-
On macOS/Linux:
source .venv/bin/activate
-
-
Install the required Python packages:
pip install -r requirements.txt
-
Build and run the RabbitMQ container using Docker Compose:
docker-compose up -d
-
Run the main script to start the RabbitMQ server:
python main.py
-
Run the publisher script to publish a test message:
python publisher.py
The RabbitMQ management console can be accessed at http://localhost:15672.
.
├── docker-compose.yaml # Docker Compose file for RabbitMQ
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── README.md # Project documentation
├── rabbitmq.py # RabbitMQ connection and operations
└── main.py # Main script to start the RabbitMQ server
└── publisher.py # Publisher script to publish a message
- Ensure that the
.env
file contains the correct RabbitMQ credentials and settings. - Make sure to start the Docker container before running any Python scripts.