1 Install the Server

$ yum install erlang
$ yum install http://www.rabbitmq.com/releases/rabbitmq-server/v2.7.0/rabbitmq-server-2.7.0-1.noarch.rpm

2 Run RabbitMQ Server:

$ /sbin/service rabbitmq-server stop/start/etc.

Server 是以用户 rabbitmq 运行的, 需要 创建一个 rabbitmq 用户, 确保拥有对 Mnesia 数据库和log的所有权.

3 create vhost:

# rabbitmqctl add_vhost /test/4730
# rabbitmqctl delete_vhost /test/4730

4 set permissions for vhost:

# rabbitmqctl  set_permissions -p /test/4739 guest ".*" ".*" ".*"

5 access control

Default database access:

a virtual host named /
a user named guest with a default password of guest, granted full access to the / virtual host.

6 configure



RabbitMQ + Python 入门


MQ(Message Queue)

RabbitMQ 使用 Elang 编写, 支持消息持久化, 基于开源的消息协议 AMQP.

AMQP 中有4个重要概念: 虚拟主机(virtual host), 交换机(exchange), 队列(queue), 绑定(binding).

  • 一个 vhost 有一组 exchange.
  • 用户只能在 vhost 的的粒度进行权限控制. 如果需要禁止 A 组访问 B 组的 exchange/queue/binding, 必须为 A/B 分别创建一个 vhost.

queue 是装消息的容器, 由消费者通过程度建立.

  • 生产者需要使用 exchange 把消息放到 queue 中. exchange 可以理解成具有路由表的路由程序. exchange 中有一系列的 binding , 即路由规则. 每个消息都有一个称为 routing key 的属性.
  • 消费者负责创建 exchanges . 每个 exchange 在独立进程中运行, 在多核的机器上创建多个 exchange , 可以充分利用 CPU .


rabbitmqctl list_queues
rabbitmqctl list_queues -p vhost_name


from amqplib import client_0_8 as amqp
conn = amqp.Connection(host='',userid='guest',passwd='guest',virtual_host='/',insist=False)
channel = conn.channel()



In the previous tutorial we created a work queue. The assumption behind a work queue is that each task is delivered to exactly one worker. In this part we’ll do something completely different – we’ll deliver a message to multiple consumers. This pattern is known as “publish/subscribe” .

The core idea in the messaging model in RabbitMQ is that the producer never sends any messages directly to a queue. Actually, quite often the producer doesn’t even know if a message will be delivered to any queue at all.

Instead, the producer can only send messages to an exchange . An exchange is a very simple thing. On one side it receives messages from producers and the other side it pushes them to queues. The exchange must know exactly what to do with a message it receives. Should it be appended to a particular queue? Should it be appended to many queues? Or should it get discarded. The rules for that are defined by the exchange type.