{"id":19036174,"url":"https://github.com/tx7do/kratos-realtimemap","last_synced_at":"2025-04-23T19:06:26.054Z","repository":{"id":43637264,"uuid":"468191799","full_name":"tx7do/kratos-realtimemap","owner":"tx7do","description":"go-kratos IoT example.","archived":false,"fork":false,"pushed_at":"2023-06-20T16:52:13.000Z","size":1014,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T02:33:33.655Z","etag":null,"topics":["consul","iot","kratos","mqtt","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tx7do.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-10T04:22:50.000Z","updated_at":"2024-12-20T04:07:08.000Z","dependencies_parsed_at":"2023-02-09T11:01:31.725Z","dependency_job_id":null,"html_url":"https://github.com/tx7do/kratos-realtimemap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fkratos-realtimemap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fkratos-realtimemap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fkratos-realtimemap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tx7do%2Fkratos-realtimemap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tx7do","download_url":"https://codeload.github.com/tx7do/kratos-realtimemap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249348729,"owners_count":21255312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consul","iot","kratos","mqtt","websocket"],"created_at":"2024-11-08T21:53:39.879Z","updated_at":"2025-04-17T14:33:56.963Z","avatar_url":"https://github.com/tx7do.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kratos-realtimemap\r\n\r\n## 实时公共交通地图\r\n\r\n源自于 [Proto.Actor](https://proto.actor/) 的一个实时地图的实例 [realtimemap-go](https://github.com/asynkron/realtimemap-go.git)\r\n\r\n它有一个在线的演示可看: \u003chttps://realtimemap.skyrise.cloud/\u003e\r\n\r\n它之前与网页端的实时数据传输用的是微软的SignalR,我这里则直接使用了Websocket.\r\n\r\n后端使用MQTT收取了一个开放的试验数据,它背后是推的一个公共交通的开放标准 [HFP API](https://digitransit.fi/en/developers/apis/4-realtime-api/vehicle-positions/) ,数据的覆盖面挺全的,该有的差不多都有了.另外谷歌也有一个基于Protobuf的开放API [GTFS](https://developers.google.com/transit/gtfs-realtime/reference).\r\n\r\n后端收取到了mqtt数据之后,正常来说是要推到kafka里面去的,然后其他的微服务按需消费:该入库的入库,该实时推给客户端的推给客户端,该缓存的缓存.但是,我偷了个懒,一切从简了.总之,入库没有入,推kafka也没推,缓存数据也只是缓存在服务的内存里面.没有缓存到Redis去.\r\n\r\n另外还有一个功能,我没有去具体实现,正常来说,设备会很多,在地图上面不可能全部的展示出来,这时候,前端地图就需要选择性的接收交通工具的实时数据,不然得爆.它是怎么做到这个事情的呢,当用户在前端切换地图的视窗的时候(放大,缩小,平移),会把它的视窗的大小和坐标推给后端,后端再根据这个视窗去裁剪,把不在视窗范围的交通工具给剪除,只留下视窗之内的交通工具.\r\n\r\n前端调用数据,使用了Restfull和Websocket结合的方式,实时的遥测坐标数据使用Websocket来推,而相对比较静态的数据,比如,地理围栏,车辆属性信息,则使用了Restfull拉取.当然了,当车辆没有实时的遥测数据的时候,其缓存的历史数据,也是可以使用Restfull来拉取的,相对来说,这也是比较静态的数据.\r\n\r\n- **注意**  \r\n**今天测试发现,mqtt接收数据接收一段时间就自动断掉了,我还以为是我这边出问题了,后来做了一些测试才发现,是对方限制了使用,限制是根据ClientID进行的验证.**\r\n\r\n## 涵盖的技术点\r\n\r\n- 使用Kratos开发微服务\r\n- 使用Kratos的BFF与网页端通讯\r\n- Kratos与MQTT的融合使用\r\n- Kratos与Websocket的融合使用\r\n\r\n## 技术栈\r\n\r\n- [Kratos](https://go-kratos.dev/)\r\n- [Consul](https://www.consul.io/)\r\n- [Jaeger](https://www.jaegertracing.io/)\r\n- [MQTT](https://mqtt.org/)\r\n- [Websocket](https://www.ruanyifeng.com/blog/2017/05/websocket.html)\r\n- [VUE](https://vuejs.org/)\r\n\r\n## Docker部署开发服务器\r\n\r\n### Consul\r\n\r\n```shell\r\ndocker pull bitnami/consul:latest\r\n\r\ndocker run -itd \\\r\n    --name consul-server-standalone \\\r\n    -p 8300:8300 \\\r\n    -p 8500:8500 \\\r\n    -p 8600:8600/udp \\\r\n    -e CONSUL_BIND_INTERFACE='eth0' \\\r\n    -e CONSUL_AGENT_MODE=server \\\r\n    -e CONSUL_ENABLE_UI=true \\\r\n    -e CONSUL_BOOTSTRAP_EXPECT=1 \\\r\n    -e CONSUL_CLIENT_LAN_ADDRESS=0.0.0.0 \\\r\n    bitnami/consul:latest\r\n```\r\n\r\n### Jaeger\r\n\r\n```shell\r\ndocker pull jaegertracing/all-in-one:latest\r\n\r\ndocker run -d \\\r\n    --name jaeger \\\r\n    -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \\\r\n    -p 5775:5775/udp \\\r\n    -p 6831:6831/udp \\\r\n    -p 6832:6832/udp \\\r\n    -p 5778:5778 \\\r\n    -p 16686:16686 \\\r\n    -p 14268:14268 \\\r\n    -p 14250:14250 \\\r\n    -p 9411:9411 \\\r\n    jaegertracing/all-in-one:latest\r\n```\r\n\r\n## 测试\r\n\r\nSwagger-UI的访问地址: \u003chttp://localhost:8800/q/swagger-ui\u003e  \r\n前台的访问地址: \u003chttp://localhost:8080/\u003e\r\n\r\n## 参考资料\r\n\r\n- [GTFS Realtime Reference](https://developers.google.com/transit/gtfs-realtime/reference)\r\n- [High-frequency positioning](https://digitransit.fi/en/developers/apis/4-realtime-api/vehicle-positions/)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftx7do%2Fkratos-realtimemap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftx7do%2Fkratos-realtimemap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftx7do%2Fkratos-realtimemap/lists"}