feat(p5): messaging, push gateway and AI assistant services

P5 阶段交付物:
- services/msg: 消息通知服务(NestJS)
  - notifications: 发送通知 + ES 全文检索 + search
  - config/elasticsearch.ts: ES Client 单例
  - package.json: 补充 @opentelemetry/sdk-node + exporter-trace-otlp-http
- services/push-gateway: WebSocket 推送网关(Go Gin)
  - internal/hub/hub.go: WebSocket 连接池管理(Register/Unregister/SendToUser)
  - internal/ws/handler.go: JWT 鉴权 + WebSocket 升级 + 内部推送 API
- services/ai: AI 辅助服务(Python FastAPI)
  - /chat + /chat/stream(SSE 流式)
  - /generate/question + /optimize/expression
  - config.py: OpenAI 兼容 API 配置
- packages/shared-proto/proto/msg.proto: NotificationService 契约(send/search)
- packages/shared-proto/proto/ai.proto: AiService 契约(含 stream 方法)
This commit is contained in:
SpecialX
2026-07-08 01:39:02 +08:00
parent 9850bfcfd1
commit 7474a92e3b
34 changed files with 1264 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
# Push Gateway 推送网关服务
> 版本0.1P5 骨架)
> 端口8081
## 职责
实时推送基础设施服务Go 实现),管理 WebSocket 长连接。
接收 Msg 服务的推送请求,维护用户在线连接池,将消息实时投递到浏览器/移动端。
## 技术栈
- Go 1.22 + Gin 1.10
- gorilla/websocket 1.5
- golang-jwt/jwt/v5JWT 鉴权)
- zap结构化日志骨架
## 开发
```bash
go mod tidy
go run main.go # :8081
```
## API
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | /healthz | 健康检查 |
| GET | /ws?token=JWT | WebSocket 升级端点JWT 鉴权) |
| POST | /internal/push | 内部推送 APIMsg 服务调用) |
## 环境变量
| 变量 | 默认值 | 说明 |
|------|--------|------|
| PUSH_GATEWAY_PORT | 8081 | 服务端口 |
| JWT_SECRET | p1-dev-secret-change-in-production | JWT 密钥 |
## WebSocket 心跳
客户端发送 `ping` 文本帧,服务端回复 `pong`