1. Hệ thống#
Hệ thống WebSocket được thiết kế để xử lý real-time data streaming, sử dụng mô hình:WebSocket (client communication)
Redis Pub/Sub (message broker)
2. Cấu trúc hệ thống#
server/: Core logic WebSocket
nginx.conf: Reverse proxy
docker-compose.yml: Deploy services
3. Logic chi tiết#
Entry Point (main.go)#
Start → Load config → Connect Redis → Init HubManager → Listen WebSocketHub Manager#
Quản lý nhiều Hub theo channel
Hub#
Register / Unregister client
Client#
Redis + Pub/Sub#
Redis → PubSub → Hub → ClientStream Worker#
Fetch data → Process → Publish RedisReplay#
Gửi lại data cũ cho client mới
Health Check#
4. Luồng hoạt động#
Client connect#
Client → /ws → Upgrade → Register HubSubscribe#
Client gửi channel → Join HubData flow#
Worker → Redis → Hub → ClientDisconnect#
5. Deployment#
6. Ưu điểm#
Tách biệt rõ ràng các layer
Modified at 2026-03-26 08:18:49