本文档描述 realtime-gateway 第一版协议草案,范围只覆盖 MVP。
/ws客户端上行 type:
authenticatejoin_channelsubscribepublishsnapshot服务端下行 type:
welcomeauthenticatedsubscribedpublishedsnapshoteventerror{
"type": "authenticate",
"role": "producer",
"token": "dev-producer-token"
}
说明:
role 可选值:producer、consumer、controllerconsumer 可允许匿名,是否启用由配置控制{
"type": "join_channel",
"role": "producer",
"channelId": "ch-xxxx",
"token": "producer-token"
}
说明:
channelId 必填token 必须和 channelId 对应role 不同,使用的 token 也不同
producerTokenconsumerTokencontrollerToken{
"type": "subscribe",
"subscriptions": [
{
"deviceId": "child-001",
"topic": "telemetry.location"
}
]
}
支持字段:
channelIddeviceIdgroupIdtopic第一版匹配规则:
{
"type": "publish",
"envelope": {
"schemaVersion": 1,
"messageId": "msg-001",
"timestamp": 1711267200000,
"topic": "telemetry.location",
"source": {
"kind": "producer",
"id": "watch-001",
"mode": "real"
},
"target": {
"channelId": "ch-xxxx",
"deviceId": "child-001",
"groupId": "class-a"
},
"payload": {
"lat": 31.2304,
"lng": 121.4737,
"speed": 1.2,
"bearing": 90,
"accuracy": 6,
"coordSystem": "GCJ02"
}
}
}
说明:
producer 和 controller 能发布channelId + deviceIdjoin_channel 加入通道,服务端会自动补全 target.channelId{
"type": "snapshot",
"subscriptions": [
{
"channelId": "ch-xxxx",
"deviceId": "child-001"
}
]
}
服务端返回:
{
"type": "snapshot",
"sessionId": "sess-2",
"state": {
"schemaVersion": 1,
"timestamp": 1711267200000,
"topic": "telemetry.location",
"source": {
"kind": "producer",
"id": "watch-001",
"mode": "real"
},
"target": {
"deviceId": "child-001"
},
"payload": {
"lat": 31.2304,
"lng": 121.4737
}
}
}
{
"type": "welcome",
"sessionId": "sess-1"
}
{
"type": "authenticated",
"sessionId": "sess-1"
}
{
"type": "subscribed",
"sessionId": "sess-1"
}
{
"type": "joined_channel",
"sessionId": "sess-1",
"state": {
"channelId": "ch-xxxx",
"deliveryMode": "cache_latest"
}
}
{
"type": "published",
"sessionId": "sess-1"
}
{
"type": "event",
"envelope": {
"schemaVersion": 1,
"timestamp": 1711267200000,
"topic": "telemetry.location",
"source": {
"kind": "producer",
"id": "watch-001",
"mode": "real"
},
"target": {
"channelId": "ch-xxxx",
"deviceId": "child-001"
},
"payload": {
"lat": 31.2304,
"lng": 121.4737
}
}
}
{
"type": "error",
"error": "authentication failed"
}
POST /api/channel/create
请求:
{
"label": "debug-a",
"deliveryMode": "cache_latest",
"ttlSeconds": 28800
}
返回:
{
"snapshot": {
"id": "ch-xxxx",
"label": "debug-a",
"deliveryMode": "cache_latest"
},
"producerToken": "....",
"consumerToken": "....",
"controllerToken": "...."
}
GET /api/admin/overviewGET /api/admin/sessionsGET /api/admin/latestGET /api/admin/channelsGET /api/admin/trafficGET /api/admin/live后续协议可以增加:
commandbatch_publishrule_eventplugin_statusreplay_controlauth_refresh