API 接口参考
本文档详细介绍 FluxMQ 2.1.1 版本中所有 HTTP API 接口,按照功能模块进行分类。
基础信息
- 基础路径: 根据模块不同,基础路径不同
- 认证方式: 支持 HTTP Basic Auth 和 Token 认证
- 内容类型:
application/json - 字符编码: UTF-8
端点管理 API
添加端点
添加新的 MQTT 端点。
请求
POST /endpoints/add
Content-Type: application/json
请求体
{
"id": "endpoint-1883",
"port": 1883,
"useWebsocket": false,
"enableAuth": true,
"enableAcl": true,
"messageMaxSize": 4194304,
"maxConnectionSize": 1000,
"enabled": true
}
响应
{
"code": 200,
"message": "success"
}
更新端点
更新现有端点的配置。
请求
POST /endpoints/update
Content-Type: application/json
请求体
{
"id": "endpoint-1883",
"port": 1883,
"useWebsocket": true,
"path": "/mqtt",
"enableAuth": true,
"enableAcl": true,
"messageMaxSize": 8388608
}
响应
{
"code": 200,
"message": "success"
}
删除端点
删除指定的端点。
请求
POST /endpoints/remove
Content-Type: application/json
请求体
{
"id": "endpoint-1883"
}
响应
{
"code": 200,
"message": "Endpoint configuration removed successfully"
}
查询端点列表
获取所有端点的配置信息。
请求
GET /endpoints/list
响应
{
"endpoints": {
"endpoint-1883": {
"id": "endpoint-1883",
"port": 1883,
"useWebsocket": false,
"enableAuth": true,
"enableAcl": true,
"messageMaxSize": 4194304,
"enabled": true
}
}
}
查询端点状态
获取指定端点的运行状态。
请求
GET /endpoints/status?id=endpoint-1883
响应
{
"id": "endpoint-1883",
"running": true,
"endpointNumber": 45
}
检查端口可用性
检查指定端口是否可用。
请求
GET /endpoints/check-port?port=1884
响应
{
"port": 1884,
"available": true
}
系统管理 API
系统配置
获取系统配置信息。
请求
GET /system/config
响应
{
"mqtt": {
"port": 1883,
"host": "0.0.0.0"
},
"http": {
"port": 8080,
"host": "0.0.0.0"
},
"cluster": {
"enabled": false
}
}
系统健康检查
检查系统健康状态。
请求
GET /health
响应
{
"status": "UP",
"timestamp": "2024-02-15T10:45:00Z"
}
集群信息
获取集群节点信息。
请求
GET /public/cluster
响应
{
"nodes": [
{
"id": "node-1",
"address": "127.0.0.1",
"status": "active"
}
]
}
配置导出
导出系统配置。
请求
GET /system/config/export
响应
{
"config": "...",
"timestamp": "2024-02-15T10:45:00Z"
}
配置导入
导入系统配置。
请求
POST /api/system/config/import
Content-Type: application/json
请求体
{
"config": "..."
}
MQTT 连接管理 API
查询连接
查询 MQTT 连接信息。
请求
POST /mqtt/connection
Content-Type: application/json
请求体
{
"page": 1,
"size": 20,
"clientId": "client-001",
"username": "user1"
}
响应
{
"data": [
{
"clientId": "client-001",
"username": "user1",
"ip": "127.0.0.1",
"port": 12345,
"connectTime": "2024-02-15T10:00:00Z",
"lastActivity": "2024-02-15T10:45:00Z"
}
],
"total": 1,
"page": 1,
"size": 20
}
关闭连接
关闭指定的 MQTT 连接。
请求
POST /mqtt/connection/close
Content-Type: application/json
请求体
{
"clientId": "client-001"
}
响应
{
"code": 200,
"message": "Connection closed successfully"
}
断开连接
断开指定的 MQTT 连接。
请求
POST /mqtt/connection/down
Content-Type: application/json
请求体
{
"clientId": "client-001"
}
连接运行时信息
获取连接运行时信息。
请求
POST /mqtt/connection/runtime
Content-Type: application/json
请求体
{
"clientId": "client-001"
}
API 连接查询
通过 API 查询连接信息。
请求
POST /api/mqtt/connection
Content-Type: application/json
消息发布 API
发布消息
发布 MQTT 消息。
请求
POST /api/publish
Content-Type: application/json
请求体
{
"topic": "sensor/temperature",
"payload": "25.5",
"qos": 1,
"retain": false,
"clientId": "http-publisher"
}
响应
{
"code": 0
}
连接检查
检查连接状态。
请求
POST /api/check
Content-Type: application/json
请求体
{
"clientId": "client-001"
}
关闭连接
关闭连接。
请求
POST /api/close
Content-Type: application/json
请求体
{
"clientId": "client-001"
}
主题管理 API
查询主题
查询主题信息。
请求
POST /topic/query
Content-Type: application/json
请求体
{
"page": 1,
"size": 20,
"topic": "sensor/#"
}
响应
{
"data": [
{
"topic": "sensor/temperature",
"subscribers": 5,
"lastMessage": "2024-02-15T10:45:00Z"
}
],
"total": 1,
"page": 1,
"size": 20
}
主题连接查询
查询主题连接信息。
请求
POST /topic/connect/query
Content-Type: application/json
订阅管理 API
本地订阅
创建本地订阅。
请求
POST /api/local/subscribe
Content-Type: application/json
请求体
{
"topic": "sensor/#",
"qos": 1
}
连接订阅
为连接添加订阅。
请求
POST /mqtt/connection/subscribe
Content-Type: application/json
请求体
{
"clientId": "client-001",
"topic": "sensor/#",
"qos": 1
}
代理订阅
添加代理订阅。
请求
POST /mqtt/proxy/subscribe/add
Content-Type: application/json
请求体
{
"topic": "sensor/#",
"qos": 1
}
查询代理订阅
查询代理订阅状态。
请求
POST /mqtt/proxy/subscribe/status
Content-Type: application/json
删除代理订阅
删除代理订阅。
请求
POST /mqtt/proxy/subscribe/delete
Content-Type: application/json
请求体
{
"topic": "sensor/#"
}
规则引擎 API
添加规则
添加规则引擎规则。
请求
POST /rule/add
Content-Type: application/json
请求体
{
"name": "temperature-rule",
"sql": "SELECT * FROM 'sensor/temperature'",
"actions": [
{
"type": "save_mysql",
"config": {
"table": "temperature_data"
}
}
]
}
响应
"success"
查询规则
查询规则列表。
请求
POST /rule/query
Content-Type: application/json
请求体
{
"page": 1,
"size": 20,
"name": "temperature"
}
删除规则
删除规则。
请求
POST /rule/delete
Content-Type: application/json