A comprehensive collection of RabbitMQ examples and tutorials implemented in Python. This repository demonstrates various messaging patterns and use cases with RabbitMQ message broker.
Created by Reza Mobaraki
- General info
- Technologies
- Prerequisites
- Setup
- Usage Examples
- Help
- Learning Resources
- Credits
- Contributors
- License
This repository contains practical examples of RabbitMQ implementation using Python and the Pika library. Each numbered directory demonstrates different messaging patterns:
- Directory 1: Basic message sending and receiving
- Directory 2: Work queues and task distribution
- Directory 3: Publish/Subscribe pattern
- Directory 4: Routing with direct exchange
- Directory 5: Topic exchanges and pattern matching
- Directory 6: RPC (Remote Procedure Call) pattern
- new Sample MQ: Advanced consumer/producer examples with utilities
These examples progress from simple point-to-point messaging to complex routing and RPC patterns, making it easy to learn RabbitMQ concepts step by step.
This project is built with:
- Python: 3.9+
- pika: 1.2.0 (Python client for RabbitMQ)
- pika-stubs: 0.1.3 (Type hints for pika)
- RabbitMQ: Message broker (requires separate installation)
If you find any issues or want to contribute improvements:
- Report Issues: Open an issue on GitHub with detailed description
- Contribute: Fork the repository, make your changes, and submit a pull request
- Suggest Improvements: Add modern technologies or messaging patterns
All contributors will be acknowledged in the credits section.
Before running these examples, you need to have RabbitMQ server installed and running:
- Ubuntu/Debian:
sudo apt-get install rabbitmq-server
- macOS:
brew install rabbitmq
- Windows: Download from RabbitMQ official website
- Docker:
docker run -d --hostname rabbitmq --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
sudo systemctl start rabbitmq-server
# or
sudo service rabbitmq-start
- Step 1: Create virtual environment
python -m venv venv
# or
virtualenv -p python3 venv
- Step 2: Activate virtual environment
# Linux/macOS
source venv/bin/activate
# Windows
venv\Scripts\activate
- Step 3: Install dependencies
pip install -r requirements.txt
- Step 4: Run examples
Navigate to any numbered directory and run the examples:
# Terminal 1 - Start receiver/consumer
cd 1
python receiver.py
# Terminal 2 - Send messages
cd 1
python sender.py
Each directory contains specific messaging patterns:
cd 1
python receiver.py # In terminal 1
python sender.py # In terminal 2
cd 2
python receiver.py # Workers (can run multiple)
python sender.py # Task producer
cd 6
python server.py # RPC server
python client.py # RPC client
Distributed under the MIT License. See license for more information.