一、使用docker安装部署rabbitmq
步骤:
1、先使用docker search 命令搜索rabbitmq镜像
命令:
docker search rabbitmq
下载后缀名management才是web应用
[root@localhost ~]# docker search rabbitmq
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/rabbitmq RabbitMQ is an open source multi-protocol ... 2878 [OK]
docker.io docker.io/bitnami/rabbitmq Bitnami Docker Image for RabbitMQ 36 [OK]
docker.io docker.io/tutum/rabbitmq Base docker image to run a RabbitMQ server 20
docker.io docker.io/frodenas/rabbitmq A Docker Image for RabbitMQ 12 [OK]
docker.io docker.io/kbudde/rabbitmq-exporter rabbitmq_exporter for prometheus 12 [OK]
docker.io docker.io/cyrilix/rabbitmq-mqtt RabbitMQ MQTT Adapter 8 [OK]
docker.io docker.io/arm32v7/rabbitmq RabbitMQ is an open source multi-protocol ... 7
docker.io docker.io/gonkulatorlabs/rabbitmq DEPRECATED: See maryville/rabbitmq 5 [OK]
docker.io docker.io/aweber/rabbitmq-autocluster RabbitMQ with the Autocluster Plugin 4
docker.io docker.io/pivotalrabbitmq/rabbitmq-autocluster RabbitMQ with the rabbitmq-autocluster plu... 3
docker.io docker.io/pivotalrabbitmq/rabbitmq-server-buildenv Image used to build and test RabbitMQ serv... 3
docker.io docker.io/deadtrickster/rabbitmq_prometheus RabbitMQ + Prometheus RabbitMQ Exporter pl... 2
docker.io docker.io/henrylv206/rabbitmq-autocluster RabbitMQ Cluster 2 [OK]
docker.io docker.io/activatedgeek/rabbitmqadmin A rabbitmqadmin docker image for administr... 1 [OK]
docker.io docker.io/amd64/rabbitmq RabbitMQ is an open source multi-protocol ... 1
docker.io docker.io/arm64v8/rabbitmq RabbitMQ is an open source multi-protocol ... 1
docker.io docker.io/foxylion/rabbitmq Preconfigured RabbitMQ docker image with s... 1 [OK]
docker.io docker.io/riftbit/rabbitmq RabbitMQ 3.x Container based on Alpine Lin... 1
docker.io docker.io/webhostingcoopteam/rabbitmq-conf RabbitMQ Configurator for Rancher 1 [OK]
docker.io docker.io/ekesken/rabbitmq docker image for rabbitmq that is configur... 0 [OK]
docker.io docker.io/i386/rabbitmq RabbitMQ is an open source multi-protocol ... 0
docker.io docker.io/newsdev/rabbitmq rabbitmq:olympics Extends official rabbitm... 0 [OK]
docker.io docker.io/pdffiller/rabbitmq Rabbitmq 3.7.3 with delayed_message plugin... 0
docker.io docker.io/ppc64le/rabbitmq RabbitMQ is an open source multi-protocol ... 0
docker.io docker.io/s390x/rabbitmq RabbitMQ is an open source multi-protocol ... 0
2、下拉rabbitmq镜像,命令:
docker pull rabbitmq
[root@localhost ~]# docker pull rabbitmq:3.7-management
Trying to pull repository docker.io/library/rabbitmq ...
3.7-management: Pulling from docker.io/library/rabbitmq
7ddbc47eeb70: Already exists
c1bbdc448b72: Already exists
8c3b70e39044: Already exists
45d437916d57: Already exists
916459a32f87: Already exists
4d9f87659206: Already exists
9ac7cc9402cf: Already exists
ed8334d30089: Pull complete
8a1a430bf7d1: Pull complete
c713bbcae751: Pull complete
b25a494b2f64: Pull complete
45bcb95d1421: Pull complete
Digest: sha256:88aac969a57849f5e52e44e9d28ff87e14fe3a4e336e360704615ca9b36ff257
Status: Downloaded newer image for docker.io/rabbitmq:3.7-management
[root@localhost ~]#
3、查看镜像信息:docker images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/rabbitmq 3.7-management ba9b3eff5cd7 2 days ago 179 MB
docker.io/rabbitmq latest 843e6712e712 2 days ago 150 MB
docker.io/zookeeper latest e41846a619f5 2 weeks ago 224 MB
docker.io/mysql latest c8ee894bd2bd 3 weeks ago 456 MB
docker.io/redis latest de25a81a5a0b 3 weeks ago 98.2 MB
[root@localhost ~]#
4、使用docker命令运行rabbitmq镜像
命令:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.7-management
[root@localhost ~]# docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.7-management
16ec0ff8a9880e6ece0e0965ad4f2c643062b378bbaa216cac7aae8bef4cc61a
5、使用docker ps 查看当前运行的镜像
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16ec0ff8a988 rabbitmq:3.7-management "docker-entrypoint..." 7 seconds ago Up 5 seconds 4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq
1bdc34911d56 redis "docker-entrypoint..." 5 hours ago Up 5 hours 0.0.0.0:6379->6379/tcp myredis
0d749348226f e41846a619f5 "/docker-entrypoin..." 2 days ago Up 7 hours 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, 8080/tcp zk01
[root@localhost ~]#
6、访问地址:虚拟机端口号+15672
默认账户和密码都是:guest
二、测试交换机
1、创建三台台交互机:
exchange.direct
exchange.topic
exchange.fanou
exchange.direct交互机创建的步骤:
exchange.fanou交互机创建的步骤:
exchange.topic交互机创建的步骤:
2、创建4台消息队列
china
china.news
china.emps
requery.news
创建步骤:
china
china.news
china.emps
requery.news
添加了4台队列:
3、消息队列创建好,想要交互,需要把消息队列与交互机绑定。
操作步骤如下:
绑定第一台交互机:exchange.direct
每台交换机绑定消息队列同样操作,忽略过了!
三台交互机与消息队列绑定好了如下:
exchange.direct
exchange.fanout
exchang.topic
4、发送消息
4.1 点对点模式:只有指定一个队列才能收到消息
比如:点击第一台交互机exchange.direct
4.2 一对多:所有队列都能收到
这台交互机:exchange.fanout绑定了所有的消息队列,所以每个消息队列都能收到消息
接着,还有一台exchange.topic交互机,这台交互机是按匹配规则发送消息。
都匹配上就能送到消息
删除获取的消息