RabbitMQ Installation and Setup — Complete Guide
In this tutorial, you will learn about RabbitMQ Installation and Setup. We cover key concepts, practical examples, and best practices to help you master this topic.
Install RabbitMQ with Docker or natively, configure the management plugin, create users and virtual hosts, and verify your setup with a test connection.
What You'll Learn
By the end of this lesson, you will have RabbitMQ running locally with the management UI, understand the default user credentials, and be able to connect from a Python client.
Why It Matters
A proper RabbitMQ installation is the foundation for all messaging patterns. Docker is the fastest way to get started. Understanding installation options helps you choose the right setup for development, staging, and production.
Real-World Use
Every DodaTech developer runs RabbitMQ locally via Docker. CI/CD pipelines use a separate RabbitMQ instance. Production uses a clustered setup across three availability zones.
Docker Installation
docker run -d \
--name rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
-e RABBITMQ_DEFAULT_USER=admin \
-e RABBITMQ_DEFAULT_PASS=admin \
rabbitmq:4-management
docker logs rabbitmq --tail 5
Expected output:
2026-06-28 10:00:00.123 [info] <0.9.0> RabbitMQ 4.0.0 starting
2026-06-28 10:00:01.456 [info] <0.9.0> Management plugin started on port 15672
Ports:
5672: AMQP protocol (client connections)15672: Management HTTP API and UI
Verify Installation
curl -u admin:admin http://localhost:15672/api/overview | python3 -m json.tool
Expected output (abbreviated):
{
"management_version": "4.0.0",
"rabbitmq_version": "4.0.0",
"cluster_name": "rabbit@localhost",
"queue_totals": {
"messages": 0,
"messages_ready": 0,
"messages_unacknowledged": 0
}
}
Verifying with Python
import pika
connection = pika.BlockingConnection(
pika.ConnectionParameters(
'localhost', 5672,
credentials=pika.PlainCredentials('admin', 'admin')
)
)
channel = connection.channel()
print("Connected successfully!")
channel.queue_declare(queue='test')
print("Queue declared")
channel.queue_delete(queue='test')
connection.close()
print("Done")
Expected output:
Connected successfully!
Queue declared
Done
Native Installation (Ubuntu/Debian)
# Add RabbitMQ repository
sudo apt-get install curl gnupg debian-keyring
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc | sudo gpg --dearmor -o /usr/share/keyrings/rabbitmq-archive-keyring.gpg
# Install
sudo apt-get update
sudo apt-get install rabbitmq-server
# Enable management plugin
sudo rabbitmq-plugins enable rabbitmq_management
# Start
sudo systemctl start rabbitmq-server
sudo systemctl enable rabbitmq-server
Management UI
Open http://localhost:15672 and log in with admin/admin. The management UI provides:
- Overview: Cluster status, message rates, node health
- Connections: Active client connections
- Channels: Active channels within connections
- Exchanges: All exchanges with bindings
- Queues: Queue depths, consumers, message rates
- Admin: Users, virtual hosts, permissions, policies
Common Mistakes
1. Port Conflicts
If port 5672 is already in use, specify a different host port: -p 5673:5672. Update your client connection to use port 5673.
2. Forgetting the Management Plugin
The rabbitmq:4-management image includes the management plugin. The plain rabbitmq:4 image does not. Always use the management variant for development.
3. Using Default Credentials in Production
Default guest/guest credentials only allow localhost connections. Create custom users for production with appropriate permissions.
4. Not Setting a VM Memory High-Watermark
RabbitMQ uses up to 40% of available RAM by default. On memory-constrained systems, set the watermark lower: -e RABBITMQ_VM_MEMORY_HIGH_WATERMARK=0.5.
5. Ignoring Data Persistence
Without volume mounts, queue data is lost when the container restarts. Mount a volume: -v rabbitmq_data:/var/lib/rabbitmq.
Practice Questions
1. What are the default RabbitMQ ports?
5672 for AMQP, 15672 for the management UI. Port 25672 is used for inter-node communication in clusters.
2. How do you access the RabbitMQ management UI?
Open http://localhost:15672 and log in with your credentials. The management plugin must be enabled.
3. What is the purpose of a virtual host?
Virtual hosts (vhosts) provide logical isolation within a single RabbitMQ instance. Different applications or environments use different vhosts to avoid naming conflicts.
4. How do you create a new user?
Via the management UI (Admin tab) or CLI: rabbitmqctl add_user myuser mypassword and rabbitmqctl set_permissions -p / myuser ".*" ".*" ".*".
Challenge
Set up RabbitMQ with three virtual hosts: one for development, one for staging, one for production. Create separate users for each vhost with appropriate permissions. Verify connectivity from Python clients.
FAQ
Mini Project: Installation Health Check
import pika
import sys
def check_rabbitmq(host='localhost', port=5672, user='admin', password='admin'):
try:
creds = pika.PlainCredentials(user, password)
params = pika.ConnectionParameters(host, port, credentials=creds)
conn = pika.BlockingConnection(params)
ch = conn.channel()
print(f"[OK] Connected to RabbitMQ at {host}:{port}")
print(f"[OK] AMQP protocol working")
try:
import urllib.request, json
url = f"http://{host}:15672/api/overview"
req = urllib.request.Request(url)
import base64
auth = base64.b64encode(f"{user}:{password}".encode()).decode()
req.add_header('Authorization', f'Basic {auth}')
resp = urllib.request.urlopen(req)
data = json.loads(resp.read())
print(f"[OK] Management UI accessible (v{data.get('rabbitmq_version', '?')})")
except Exception:
print("[WARN] Management UI not accessible (plugin may be disabled)")
conn.close()
return True
except Exception as e:
print(f"[FAIL] {e}")
return False
if __name__ == '__main__':
success = check_rabbitmq()
sys.exit(0 if success else 1)
Expected output:
[OK] Connected to RabbitMQ at localhost:5672
[OK] AMQP protocol working
[OK] Management UI accessible (v4.0.0)
What's Next
Now that RabbitMQ is installed, explore core concepts of exchanges, queues, and bindings, then dive into direct exchange for point-to-point messaging.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro