Server-Sent Events(SSE)在 BitzOrcas 中尚未实现。SSE 计划作为 WebSockets 的轻量级替代,用于通知流推送等单向推送场景。
计划用例
| 场景 | SSE 适配性 |
|---|---|
| 通知收件箱更新 | ✅ 理想 — 服务端推送新通知 |
| 审计日志流 | ✅ 良好 — 单向日志尾部 |
| 仪表盘指标 | ✅ 良好 — 周期性指标推送 |
| 聊天消息 | ⚠️ 可行但 SignalR 更适合双向 |
计划端点
GET /api/notifications/streamAccept: text/event-stream
→ {"type": "notification", "data": {...}}→ {"type": "notification", "data": {...}}→ {"type": "heartbeat", "data": {}}ASP.NET Core SSE 实现(计划中)
app.MapGet("/api/notifications/stream", async (HttpContext ctx) =>{ ctx.Response.Headers.ContentType = "text/event-stream"; ctx.Response.Headers.CacheControl = "no-cache";
// 将通知流式传输到客户端 await foreach (var notification in notificationStream.ReadAllAsync(ct)) { await ctx.Response.WriteAsync($"data: {JsonSerializer.Serialize(notification)}\n\n"); await ctx.Response.Body.FlushAsync(); }});