欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RabbitMQ安装与配置

程序员文章站 2022-05-11 22:21:21
...

一、安装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<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue '93bbbad7-4dcd-4f2c-930f-30f1fca50a26' in vhost '/xjsit', class-id=50, method-id=10), null, ""}

 

解决:访问http://localhost:15672/,在Admin页签中给用户设置相应配置和读写的权限。