引言
什么是AMQP?
? ? ? ? AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计。消息中间件主要用于组件之间的解耦,消息的发送者无需知道消息使用者的存在,反之亦然。AMQP的主要特征是面向消息、队列、路由(包括点对点和发布/订阅)、可靠性、安全。
什么是RabbitMQ?
? ? ? ? RabbitMQ是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOMP等,支持AJAX。用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现不俗。
如何安装RabbitMQ?
1.安装Erlang
如果安装RabbitMQ首先安装基于Erlang语言支持的OTP软件,?Erlang是一种小众的函数式语言, RabitMQ 要求Windows 安装一个 64-bit Erlang,
所以选择图片中的64-bit的 版本, 下载后得到otp_win64_24.0.exe, 直接双击安装即可
下载 https://www.erlang.org/downloads,
设置环境变量:
设置ERLANG_HOME(变量值就是你按照otp软件的路径)
修改环境变量path,增加Erlang变量至path,%ERLANG_HOME%\bin;
2.安装RabbitMQ
下载服务:
下载地址:https://www.rabbitmq.com/install-windows.html
设置环境变量
设置RABBITMQ_SERVER (变量值是rabbitmq server的安装路径)
修改环境变量path,增加RABBITMQ_SERVER变量至path,%RABBITMQ_SERVER%\sbin;
如何使用RabbitMQ Server?
命令行工具
从安装的RabbitMQ Server 中可以查看到提供的命令行工具(使用命令行工具需安装Erlang)
RabbitMQ附带多种命令行工具
- rabbitmqctl 用于服务观念里和一般操作员任务,通常支队RabbitMQ管理员可用,它提供了对节点的完全控制,虚拟主机,用户和权限管理等
- rabbitmq-diagnostics 主要用于诊断和健康检查
- rabbitmq-plugins 主要用于插件管理
- rabbitmq-queues 主要用于维护任务队列
- rabbitmq-upgrade 主要用于维护升级任务
在windows 中,上面的名称都有一个,bat后缀,如下图
? ? ?rabbitmqctl 是RabbitMQ附带的原始CLI工具。它支持广泛的操作,大部分是管理(操作)性质的
下面只介绍几种常用命令,详细信息可以参考:https://www.rabbitmq.com/cli.html
健康检查: rabbitmqctl status
使用检查执行后会显示节点的运行信息,健康检查发挥作用必须要满足两个条件
- 节点正在运行
- rabbitmqctl必须能向节点进行身份验证
如果出现以下的图,说明安装是成功的,并且说明现在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}}]
启动监控管理器:rabbitmq-plugins?enable?rabbitmq_management
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进入监控页面
?
关闭监控:rabbitmq-plugins disable rabbitmq_management
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/ 后将不再能访问到监控页面
停止服务:rabbitmq-service stop
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:
启动服务rabbitmq-service start
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmq-service start
RabbitMQ 服务正在启动 .
RabbitMQ 服务已经启动成功。
重启命令:net stop RabbitMQ && net start
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>net stop RabbitMQ && net start RabbitMQ
RabbitMQ 服务正在停止.........
RabbitMQ 服务已成功停止。
RabbitMQ 服务正在启动 .
RabbitMQ 服务已经启动成功。
帮助命令:rabbitmqctl help
命令行提供了很多颗执行的命令,例如:查看所有的队列:rabbitmqctl list_queues ,清除所有的队列:rabbitmqctl reset
查看更多信息可以使用rabbitmqctl help
C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.14\sbin>rabbitmqctl help
[1mUsage[0m
rabbitmqctl [--node <node>] [--timeout <timeout>] [--longnames] [--quiet] <command> [<command options>]
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 <command>' to learn more about a specific command
常见问题
启动异常:发生系统错误 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原理以及源码分析
|