This project demonstrates the use of RabbitMQ with Python, showcasing two message handling patterns:
- Pub/Sub (Publisher/Subscriber)
- Queue-based messaging.
Using Docker to set up RabbitMQ and its management interface. Python scripts are provided to simulate the interaction with the RabbitMQ message broker for both pub/sub and queue-based communication.
.
├── README.md
├── docker-compose.yml
├── rabbit-pub_sub
│ ├── pub.py # Publisher script
│ └── sub.py # Subscriber script
├── rabbit-queue
│ ├── consumer.py # Consumer script
│ └── producer.py # Producer script
└── requirements.txt # Python dependencies
The provided docker-compose.yml
file launches a RabbitMQ container with the management interface.
To start the container:
docker-compose up -d
This will:
- Launch RabbitMQ on port 5672 (for messaging).
- Make the RabbitMQ management UI available on port 15672.
Before running the Python scripts, install the necessary dependencies:
pip install -r requirements.txt
The publisher script (pub.py
) announces new flavors by sending messages to a topic exchange named flavors
.
Run the publisher:
python rabbit-pub_sub/pub.py
The subscriber script (sub.py
) listens for new flavor announcements by consuming messages from the flavors
exchange.
Run the subscriber:
python rabbit-pub_sub/sub.py
The producer script (producer.py
) sends new ice cream orders to a queue named sorvete_queue
.
Run the producer:
python rabbit-queue/producer.py
The consumer script (consumer.py
) listens to the sorvete_queue
and processes orders.
Run the consumer:
python rabbit-queue/consumer.py