作者介绍:简历上没有一个精通的运维工程师,下面的思维导图也是预计更新的内容和当前进度(不定时更新)。
中间件,我给它的定义就是为了实现某系业务功能依赖的软件,包括如下部分:
Web服务器
代理服务器
ZooKeeper
Kafka
RabbitMQ(本章节)
RabbitMQ 提供的 RESTful 接口,用于无需登录Web控制台即可管理集群、监控状态、操作资源。适合自动化运维、集成监控系统(如Prometheus/Zabbix)或自定义管理工具。
1.启用与认证
启用插件,是因为启用了插件才有暴露的http接口。
rabbitmq-plugins enable rabbitmq_management
所有 API 请求需添加 Basic Auth 头,当然也可以是其他定义的管理员账号。
#当然这个操作只能在本机执行
curl -u guest:guest http://localhost:15672/api/overview
端点 | 方法 | 功能描述 |
---|---|---|
/api/nodes | GET | 获取所有节点信息 |
/api/nodes/{name} | GET | 获取特定节点详细信息 |
/api/cluster-name | GET | 获取集群名称 |
/api/healthchecks/node | GET | 节点健康检查 |
端点 | 方法 | 功能描述 |
---|---|---|
/api/vhosts | GET | 列出所有虚拟主机 |
/api/vhosts/{vhost} | PUT | 创建虚拟主机 |
/api/vhosts/{vhost} | DELETE | 删除虚拟主机 |
端点 | 方法 | 功能描述 |
---|---|---|
/api/queues | GET | 获取所有队列 |
/api/queues/{vhost}/{queue} | PUT | 声明队列 |
/api/queues/{vhost}/{queue}/contents | DELETE | 清除队列消息 |
/api/queues/{vhost}/{queue}/bindings | GET | 获取队列绑定关系 |
端点 | 方法 | 功能描述 |
---|---|---|
/api/exchanges | GET | 列出所有交换机 |
/api/exchanges/{vhost}/{exchange} | PUT | 创建交换机 |
/api/exchanges/{vhost}/{exchange} | DELETE | 删除交换机 |
端点 | 方法 | 功能描述 |
---|---|---|
/api/queues/{vhost}/{queue}/get | POST | 消费消息(拉取模式) |
/api/exchanges/{vhost}/{exchange}/publish | POST | 发布消息 |
curl -u "guest:guest" \
-X PUT \
-H "Content-Type: application/json" \
-d '{"description": "My custom VHost"}' \
http://localhost:15672/api/vhosts/my_vhost
curl -u "guest:guest" \
-X PUT \
-H "Content-Type: application/json" \
-d '{
"type": "direct",
"durable": true
}' \
http://localhost:15672/api/exchanges/my_vhost/orders.direct
curl -u "guest:guest" \
-X PUT \
-H "Content-Type: application/json" \
-d '{
"auto_delete": false,
"durable": true
}' \
http://localhost:15672/api/queues/my_vhost/my_queue
curl -u "guest:guest" \
-X POST \
-H "Content-Type: application/json" \
-d '{
"routing_key": "order.created",
"arguments": {}
}' \
http://localhost:15672/api/bindings/my_vhost/e/orders.direct/q/my_queue
curl -u "guest:guest" \
-X POST \
-H "Content-Type: application/json" \
-d '{
"properties": {},
"routing_key": "order.created",
"payload": "Hello World",
"payload_encoding": "string"
}' \
http://localhost:15672/api/exchanges/my_vhost/orders.direct/publish
4.6 消费消息
curl -u "guest:guest" \
-X POST \
-H "Content-Type: application/json" \
-d '{
"count": 5,
"ackmode": "ack_requeue_true",
"encoding": "auto",
"truncate": 50000
}' \
http://localhost:15672/api/queues/my_vhost/my_queue/get
这里未发ACK确认。当然这里只列举部分功能,更多的功能希望大家多去尝试。