# RabbitMQ — Reliable Open-Source Message Broker > RabbitMQ is one of the most popular open-source message brokers, implementing AMQP, MQTT, STOMP, and more. Used by thousands of companies for reliable async messaging, RPC, pub/sub, task queues, and microservice communication. ## Install Save in your project root: ## Quick Use ```bash # Docker docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 \ -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin \ rabbitmq:3-management # UI at http://localhost:15672 ``` Python producer (pika): ```python import pika conn = pika.BlockingConnection(pika.ConnectionParameters("localhost")) channel = conn.channel() channel.queue_declare(queue="tasks", durable=True) channel.basic_publish( exchange="", routing_key="tasks", body="process order 42", properties=pika.BasicProperties(delivery_mode=2), # persistent ) conn.close() ``` Python consumer: ```python def callback(ch, method, properties, body): print(f"Received {body}") ch.basic_ack(delivery_tag=method.delivery_tag) channel.basic_qos(prefetch_count=1) channel.basic_consume(queue="tasks", on_message_callback=callback) channel.start_consuming() ``` ## Intro RabbitMQ is one of the most popular and mature open-source message brokers. Originally built on Erlang/OTP (still its core), it implements the Advanced Message Queuing Protocol (AMQP) and supports MQTT, STOMP, HTTP, WebSocket. Used by thousands of companies for reliable async messaging, task queues, pub/sub, and microservice communication. - **Repo**: https://github.com/rabbitmq/rabbitmq-server - **Stars**: 13K+ - **Language**: Erlang - **License**: MPL 2.0 ## What RabbitMQ Does - **AMQP 0.9.1** — primary protocol, plus AMQP 1.0 - **Exchanges** — direct, fanout, topic, headers - **Queues** — classic, quorum (Raft-based), streams (append-only log) - **Bindings** — flexible routing rules - **Persistence** — durable exchanges/queues + persistent messages - **Clustering** — high availability across nodes - **Mirrored/Quorum queues** — HA with replication - **Plugins** — MQTT, STOMP, Federation, Shovel, Web STOMP - **Management UI** — http://host:15672 - **RabbitMQ Streams** — append-only log (Kafka-like) ## Architecture Erlang processes are cheap and fault-tolerant. A RabbitMQ node runs thousands of Erlang processes per queue/connection. Cluster nodes share metadata via Mnesia DB (or Khepri in newer versions). Messages route through exchanges by binding rules. ## Self-Hosting ```yaml # docker-compose.yml with clustering version: "3" services: rabbit1: image: rabbitmq:3-management hostname: rabbit1 environment: RABBITMQ_ERLANG_COOKIE: "secretcookie" rabbit2: image: rabbitmq:3-management hostname: rabbit2 depends_on: [rabbit1] environment: RABBITMQ_ERLANG_COOKIE: "secretcookie" ``` ## Key Features - AMQP, MQTT, STOMP protocols - Multiple exchange types - Quorum queues (Raft) - Streams (Kafka-like append log) - Federation across clusters - Shovel for cross-cluster forwarding - Management UI and HTTP API - Plugins ecosystem - TLS and SASL auth - Mature client libraries for every language ## Comparison | Broker | Protocol | Model | Best For | |---|---|---|---| | RabbitMQ | AMQP + more | Queues + exchanges | Task queues, RPC, flexible routing | | Kafka | Kafka | Distributed log | Event streaming, analytics | | NATS | NATS | Subject-based pub/sub | Low-latency microservice comms | | Redis Streams | Redis | Log + consumer groups | Lightweight streams | | ActiveMQ | AMQP + JMS | Queues + topics | Legacy Java systems | ## 常见问题 FAQ **Q: RabbitMQ vs Kafka?** A: RabbitMQ 是传统 MQ(灵活路由、任务队列、RPC、低延迟异步);Kafka 是分布式日志(事件流、长期保留、高吞吐)。选择看是队列语义还是流语义。 **Q: Classic vs Quorum queue?** A: Quorum 是 v3.8+ 基于 Raft 的新 HA queue 类型,推荐生产使用。Classic mirrored queue 在 v3.12 后 deprecated。 **Q: 多大规模?** A: 单节点支持数万连接、每秒几万消息。集群能 scale 到更高。超高吞吐(百万/秒)建议 Kafka。 ## 来源与致谢 Sources - Docs: https://www.rabbitmq.com/documentation.html - GitHub: https://github.com/rabbitmq/rabbitmq-server - License: MPL 2.0 --- Source: https://tokrepo.com/en/workflows/90136d3b-35f6-11f1-9bc6-00163e2b0d79 Author: AI Open Source