一、安装Rabbit MQ
1. 下载并安装Erlang:http://www.erlang.org/downloads
2. 下载并安装Rabbit MQ:http://www.rabbitmq.com/releases/rabbitmq-server/
默认安装的Rabbit MQ 监听端口是15672
二、Rabbit MQ配置和运行
1. 激活管理插件
切换到sbin目录下,执行:rabbitmq-plugins enable rabbitmq_management
重启服务使其生效:net stop RabbitMQ && net start RabbitMQ
2. 创建用户
创建用户admin,密码为admin123:rabbitmqctl add_user admin admin123
给admin赋予管理员administrator角色:rabbitmqctl set_user_tags admin administrator
查看用户列表:rabbitmqctl list_users
创建vhost:rabbitmqctl add_vhost /myhost
查看vhost:rabbitmqctl list_vhosts
赋予用户admin具有/myhost这个virtual host中所有资源的配置、写、读权限以便管理其中的资源: rabbitmqctl set_permissions -p /myhost admin '.*' '.*' '.*'
常见问题
1. 支持使用IP访问
在etc\rabbitmq.config.example中增加如下配置:
{tcp_listeners, [15672]},
{loopback_users, ["admin"]},
2. 报如下异常
org.springframework.context.ApplicationContextException: Failed to start bean 'amqpTemplate.replyListener'; nested exception is org.springframework.amqp.AmqpIllegalStateException: Fatal exception on listener startup
Caused by: org.springframework.amqp.AmqpIllegalStateException: Fatal exception on listener startup
Caused by: org.springframework.amqp.rabbit.listener.FatalListenerStartupException: Cannot prepare queue for listener. Either the queue doesn't exist or the broker will not allow us to use it.
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method
解决:访问http://localhost:15672/,在Admin页签中给用户设置相应配置和读写的权限。