本文档用于整理当前 realtime-gateway 的构建、运行、联调和排障方式,覆盖今天已经落地的能力。
当前工程由 3 部分组成:
D:\dev\cmr-mini\realtime-gatewayD:\dev\cmr-mini\tools\mock-gps-simD:\dev\cmr-mini\doc当前推荐的本地开发方式:
中转服务器在整个系统里,应当被当成“实时中枢”来使用,而不是业务主服务器的一部分。
当前建议的角色分工:
Producer
Consumer
Controller
Business Server
系统里的基本流向应当是:
Producer -> Gateway -> Consumer / Plugin -> Business Server
也就是说:
本地开发建议统一使用以下端口:
1786518080对应地址:
http://127.0.0.1:17865/ws://127.0.0.1:17865/mock-gpshttp://127.0.0.1:18080/ws://127.0.0.1:18080/wscd D:\dev\cmr-mini\realtime-gateway
go build -o .\bin\gateway.exe .\cmd\gateway
cd D:\dev\cmr-mini\realtime-gateway
go build -o .\bin\mock-producer.exe .\cmd\mock-producer
go build -o .\bin\mock-consumer.exe .\cmd\mock-consumer
cd D:\dev\cmr-mini\realtime-gateway
go build ./...
开发期建议直接使用 Tunnel 开发配置:
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\gateway -config .\config\tunnel-dev.json
如果只想本机用默认开发配置:
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\gateway -config .\config\dev.json
在仓库根目录:
cd D:\dev\cmr-mini
npm run mock-gps-sim
http://127.0.0.1:18080/http://127.0.0.1:17865/如果页面和实际代码不一致,先强刷一次:
Ctrl + F5
新网关管理台已经包含:
相关接口:
/api/admin/overview/api/admin/sessions/api/admin/latest/api/admin/channels/api/admin/traffic/api/admin/livecd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\gateway -config .\config\tunnel-dev.json
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-consumer -config .\config\consumer-gps-heart.example.json
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-producer -device-id child-001 -topic telemetry.location -count 5
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-producer -device-id child-001 -topic telemetry.heart_rate -bpm 148 -count 5
这是当前最推荐的开发联调方式。
ws://127.0.0.1:18080/wsProducer Token / Channel TokenChannel ID 可选Device IDGroup IDSource IDSource Mode这样可以同时保留:
今天这个阶段,最推荐这样用:
这个组合的好处是:
当前网关支持两种生产者接入模式。
不使用 channel,直接走 authenticate:
{"type":"authenticate","role":"producer","token":"dev-producer-token"}
适合:
先创建 channel,再用 join_channel:
{"type":"join_channel","role":"producer","channelId":"ch-xxxx","token":"<producerToken>"}
适合:
drop_if_no_consumer / cache_latest 策略在管理台可直接创建 channel,返回:
channelIdproducerTokenconsumerTokencontrollerToken老模拟器现在已经支持:
Channel ID:走老的 authenticateChannel ID:自动走 join_channel所以如果你在管理台里创建了 channel:
Channel ID 填 channelIdProducer Token / Channel Token 填 producerToken两者必须配套使用。
当前 channel 支持两种分发策略:
cache_latest
drop_if_no_consumer
适用建议:
drop_if_no_consumercache_latest“实时数据窗口”当前支持:
topic 过滤channelId 过滤deviceId 过滤channelId / deviceId 聚合建议使用方式:
channelIddeviceId网关已累计以下指标:
Published
Dropped
Fanout
同时支持:
topic 统计channel 统计这几个指标适合用来观察:
drop_if_no_consumer 是否正在生效cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\gateway -config .\config\tunnel-dev.json
cd D:\dev\cmr-mini
npm run mock-gps-sim
cd D:\dev\cmr-mini\realtime-gateway
go build ./...
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-producer -device-id child-001 -topic telemetry.location -count 5
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-producer -device-id child-001 -topic telemetry.heart_rate -bpm 148 -count 5
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-producer -channel-id ch-xxxx -token <producer-token> -topic telemetry.location -count 5
cd D:\dev\cmr-mini\realtime-gateway
go run .\cmd\mock-consumer -channel-id ch-xxxx -token <consumer-token> -topics telemetry.location,telemetry.heart_rate
authentication failed通常是这两种情况:
producerToken,但没填 channelIdauthenticate处理方式:
Channel ID 和对应 producerTokenChannel ID 留空dev-producer-token当前开发统一使用 18080。
如果页面还显示旧地址:
Ctrl + F5这通常是浏览器缓存旧前端资源。
处理方式:
http://127.0.0.1:18080/Ctrl + F5先检查:
18080channelId / deviceId 过滤今天这个阶段,最稳的开发方式是:
这也是当前最省风险的组合。