AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计。消息中间件主要用于组件之间的解耦,消息的发送者无需知道消息使用者的存在,反之亦然。AMQP的主要特征是面向消息、队列、路由(包括点对点和发布/订阅)、可靠性、安全。
RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOMP等,支持AJAX。用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现不俗。
文章列表
1-RabbitMQ Server简介和安装教程
2-RabbitMQ概念 AMQP模型
3-RabbitMQ教程第一步Hello World
4-RabbitMQ教程工作队列Work queues
5-RabbitMQ教程扇出交换器和发布订阅
6-RabbitMQ教程直连交换器和路由Routing
7-RabbitMQ教程主题交换器Topics
8-RabbitMQ教程远程过程调用RPC
9-RabbitMQ教程发布确认PublishConfirm
如果安装RabbitMQ首先安装基于Erlang语言支持的OTP软件, Erlang是一种小众的函数式语言, RabitMQ 要求Windows 安装一个 64-bit Erlang,
所以选择图片中的64-bit的 版本, 下载后得到otp_win64_24.0.exe, 直接双击安装即可
下载 Downloads - Erlang/OTP,
设置环境变量:
设置ERLANG_HOME(变量值就是你按照otp软件的路径)
修改环境变量path,增加Erlang变量至path,%ERLANG_HOME%\bin;
下载服务:
下载地址:Installing on Windows — RabbitMQ
设置环境变量
设置RABBITMQ_SERVER (变量值是rabbitmq server的安装路径)
修改环境变量path,增加RABBITMQ_SERVER变量至path,%RABBITMQ_SERVER%\sbin;
命令行工具
从安装的RabbitMQ Server 中可以查看到提供的命令行工具(使用命令行工具需安装Erlang)
RabbitMQ附带多种命令行工具
在windows 中,上面的名称都有一个,bat后缀,如下图
rabbitmqctl 是RabbitMQ附带的原始CLI工具。它支持广泛的操作,大部分是管理(操作)性质的
下面只介绍几种常用命令,详细信息可以参考:Command Line Tools — RabbitMQ
使用检查执行后会显示节点的运行信息,健康检查发挥作用必须要满足两个条件
如果出现以下的图,说明安装是成功的,并且说明现在RabbitMQ Server已经启动了,运行正常
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmqctl status
Status of node rabbit@star10001874 ...
[{pid,17612},
{running_applications,[{ranch,"Socket acceptor pool for TCP protocols.",
"1.7.1"},
{ssl,"Erlang/OTP SSL application","9.2"},
{public_key,"Public key infrastructure","1.6.5"},
{asn1,"The Erlang ASN1 compiler version 5.0.8",
# 略
{alarms,[]},
{listeners,[]},
{vm_memory_calculation_strategy,rss},
{processes,[{limit,1048576},{used,121}]},
{run_queue,0},
{uptime,2341},
{kernel,{net_ticktime,60}}]
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@star10001874:
rabbitmq_management
The following plugins have been configured:
rabbitmq_management
rabbitmq_management_agent
rabbitmq_web_dispatch
Applying plugin configuration to rabbit@star10001874...
Plugin configuration unchanged.
启动后就可以访问:http://localhost:15672/ 使用guest/guest进入监控页面
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmq-plugins disable rabbitmq_management
Disabling plugins on node rabbit@star10001874:
rabbitmq_management
All plugins have been disabled.
Applying plugin configuration to rabbit@star10001874...
The following plugins have been disabled:
rabbitmq_management_agent
rabbitmq_web_dispatch
rabbitmq_management
stopped 3 plugins.
关闭监控后访问:http://localhost:15672/ 后将不再能访问到监控页面
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmq-service stop
RabbitMQ 服务正在停止......
RabbitMQ 服务已成功停止。
#停止后使用rabbitmqctl status 查看时候结果就发生变化
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmqctl status
Status of node rabbit@star10001874 ...
Error: unable to perform an operation on node 'rabbit@star10001874'. Please see diagnostics information and suggestions below.
Most common reasons for this are:
* Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
* CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
* Target node is not running
In addition to the diagnostics info below:
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmq-service start
RabbitMQ 服务正在启动 .
RabbitMQ 服务已经启动成功。
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>net stop RabbitMQ && net start RabbitMQ
RabbitMQ 服务正在停止.........
RabbitMQ 服务已成功停止。
RabbitMQ 服务正在启动 .
RabbitMQ 服务已经启动成功。
命令行提供了很多颗执行的命令,例如:查看所有的队列:rabbitmqctl list_queues ,清除所有的队列:rabbitmqctl reset
查看更多信息可以使用rabbitmqctl help
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmqctl help
[1mUsage[0m
rabbitmqctl [--node ] [--timeout ] [--longnames] [--quiet] []
Available commands:
[1mHelp[0m:
help Displays usage information for a command
version Displays CLI tools version
[1mNodes[0m:
await_startup Waits for the RabbitMQ application to start on the target node
reset Instructs a RabbitMQ node to leave the cluster and eturn to its virgin state
# 省率中间
[1mOperations[0m:
close_all_connections Instructs the broker to close all connections for the specified vhost or entire RabbitMQ node
close_connection Instructs the broker to close the connection associated with the Erlang process id
eval Executes Erlang code on the RabbitMQ node
exec Executes Elixir code on the CLI node
force_gc Makes all Erlang processes on the target node perform/schedule a full sweep garbage collection
hipe_compile Performs HiPE-compilation of [some] server modules to the given directory to be used with RABBITMQ_SERVE
[1mQueues[0m:
delete_queue Deletes a queue
purge_queue Purges a queue (removes all messages in it)
Use 'rabbitmqctl help ' to learn more about a specific command
其他命令列表
rabbitmqctl list_queues |
查看所有队列 |
rabbitmqctl reset |
清除所有队列 |
rabbitmqctl list_exchanges |
查看所有交换器 |
rabbitmqctl add_user username password |
添加用户 |
rabbitmqctl set_user_tags username administrator |
分配角色 |
rabbitmqctl list_bindings | 查看交换器和队列的绑定关系 |
启动异常:发生系统错误 5。拒绝访问。
net stop RabbitMQ && net start RabbitMQ
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmq-service start
发生系统错误 5。
拒绝访问。
处理方法: 5代表不是系统管理员权限,因此以管理员身份启动Windows的命令行时就可避免这个问题
上一篇: SpringSession原理以及源码分析