fix endpoint

This commit is contained in:
anlicheng 2025-11-06 16:50:46 +08:00
parent 66f7e1deff
commit 854b657ec5

View File

@ -1,63 +1,69 @@
## Endpoint管理
## Endpoint数据结构
### 获取全部的Endpoint
### 数据库表结构
```html
method: GET
url: /endpoint/all
返回数据:
[
{
"name": "名称",
"title": "中电集团"
"matcher": "匹配的正则表达式",
"protocol": "http|https|websocket|mqtt|kafka",
"config": "参考config格式说明"
}
]
```mysql
CREATE TABLE `endpoint` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称,路由时基于名称',
`title` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '序列号',
`type` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '类型',
`config_json` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '配置信息基于json格式存储',
`status` smallint NOT NULL DEFAULT '-1',
`creator` smallint NOT NULL DEFAULT '0' COMMENT '创建人',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
```
### 创建Endpoint
### config_json中的数据配置
```html
method: POST
url: /endpoint/create
body: (content-type: application/json)
{"name": $name, "matcher": $matcher, "title": $title, "protocol": "http|https|websocket|kafka|mqtt", "config": "参考config格式说明"}
#### http方式: type=http
```json
说明:
name是唯一的不同的终端名称代表不同的接受端
{
"url": "http(s)://www.test.com/api",
"pool_size": 10
}
```
### 删除Endpoint
```html
method: POST
url: /endpoint/delete
body: (content-type: application/json)
{"name": $name}
#### mqtt方式, type=mqtt
```json
{
"host": "127.0.0.1",
"port": 3361,
"client_id": "ClientIdOfMqtt",
"username": "root",
"password": "Password1234",
"topic": "mqtt_topic",
"qos": 0
}
```
### config格式说明
```html
#### kafka方式, type=kafka
其中sasl_config可以不配置
```json
http|https
{"url": "http(s)://xx.com"}
{
"bootstrap_servers": ["127.0.0.1:9090", "192.168.1.1:9090"],
"topic": "KafkaTopic",
"sasl_config": {
"username": "root",
"password": "password1234",
"mechanism": "sha_256|sha_512|plain"
}
}
```
websocket
{"url": "ws://xx.com/ws"}
### 关于name的规则说明
```text
边缘端的微服务在数据上传的时候需要指定routing_key, 服务器端收到数据后会根据 routing_key = name 对数据进行路由
kafka:
{"bootstrap_server": ["localhost:9092"], "topic": "test", "username": "test", "password": "password1234"}
mysql:
{"host": "localhost", port: 3306, "username": "test", "password": "test1234", "database": "iot", "table_name": "north_data"}
mqtt:
{"host": "localhost", port: 1883, "username": "test", "password": "test1234", "topic": "CET/NX/${location_code}/upload", "qos": 0|1|2}
topic中支持预定义变量: ${location_code}; 发送的时候会替换成对应的点位编码
```
```