feat(gateway): SSE token 流可回放 + 断点续传(Redis Stream)

根治 core NATS 不回放导致的"连晚/刷新/抖动重连丢实时 token":
- store/redis:token 流落 Redis Stream(XADD,带 TTL)——StreamAppend /
  StreamRead(XREAD BLOCK,支持从任意 ID 续读)。
- gateway:SubmitTask 起即启动 token 录制器(订阅早于 dispatcher 产 token,
  全量捕获,与 SSE 客户端是否在线无关);StreamTask 改从 Redis Stream 读,
  发 SSE 时带 id(= Redis entry ID),浏览器重连自动带 Last-Event-ID 续传。
  Redis 降级时回退原 live-NATS 路径(streamTaskLive)。

实测:任务跑完后才连 SSE → 完整回放;带 Last-Event-ID 重连 → 断点续传不重不漏;
make test-go 全绿。最终答复本就持久在 Redis 历史,此改让"实时流"也无损。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-06-23 15:05:53 +08:00
parent 79437e1c1c
commit 529cd0fdd6
3 changed files with 114 additions and 5 deletions
+1 -1
View File
@@ -4,6 +4,7 @@ go 1.25.0
require (
github.com/bwmarrin/snowflake v0.3.0
github.com/gin-contrib/sse v0.1.0
github.com/gin-gonic/gin v1.10.0
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/minio/minio-go/v7 v7.2.0
@@ -26,7 +27,6 @@ require (
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect