RabbitMQ学习

摘要:RabbitMQ学习

安装(docker-compose方式)

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: '3'
services:
rabbitmq:
image: rabbitmq:3.12.8-management
container_name: rabbitmq # 容器名为'rabbitmq'
hostname: my-rabbit
restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
RABBITMQ_DEFAULT_USER: guest # 登录账号
RABBITMQ_DEFAULT_PASS: guest # 登录密码
#RABBITMQ_DEFAULT_VHOST: my_vhost # 虚拟host,默认为 /
volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
- "./config/enabled_plugins:/etc/rabbitmq/enabled_plugins"
- "./data:/var/lib/rabbitmq"
ports: # 映射端口
- "5672:5672"
- "15672:15672"
- "15674:15674"

config/enabled_plugins:

1
[rabbitmq_management,rabbitmq_prometheus,rabbitmq_mqtt,rabbitmq_web_stomp].

查看插件列表:

1
docker exec -it rabbitmq rabbitmq-plugins list

访问管理端:

1
http://127.0.0.1:15672

输入账号密码后登录:

1
2
username: guest
password: guest

如果guest登录不上,提示仅允许从localhost进行访问,可按照官网文档修改一下配置,即可从外部进行访问:

/etc/rabbitmq/rabbitmq.conf

1
2
3
4
5
6
7
# DANGER ZONE!
#
# allowing remote connections for default user is highly discouraged
# as it dramatically decreases the security of the system. Delete the default user
# instead and create a new one with generated secure credentials, or use JWT tokens,
# or x.509 certificates for clients to authenticate themselves
loopback_users = none