# push **Repository Path**: ThinkingT/push ## Basic Information - **Project Name**: push - **Description**: No description available - **Primary Language**: Go - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-04 - **Last Updated**: 2026-08-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Push - 分布式长连接推送系统 基于 Nginx + Go 的分布式长连接推送系统,支持 WebSocket 长连接管理、Redis 同步 SET/GET 和服务转发。 ## 架构 ``` ┌─────────────┐ WebSocket ┌─────────────────────────┐ │ 客户端 │ ────────────────> │ Nginx + ev 模块 │ │ (Agent) │ │ (WebSocket 长连接网关) │ └─────────────┘ └───────────┬─────────────┘ │ ┌───────────────────────┼───────────────┐ ▼ ▼ ▼ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ Auth │ │Heartbeat │ │ Proxy │ │ Service │ │ Service │ │ Service │ └──────────┘ └──────────┘ └──────────┘ │ │ │ └───────────────────────┼───────────────┘ ▼ ┌──────────┐ │ Redis │ │ (SET/GET)│ └──────────┘ ``` ## 目录结构 ``` push/ ├── cmd/ # 入口文件 ├── conf/ # 配置管理 ├── controller/ # REST API 控制器 ├── mgr/ # WebSocket 连接管理器 ├── service/ # 业务逻辑层 ├── ev/ # Nginx WebSocket 长连接 C 模块 ├── go.mod / go.sum # Go 模块依赖 └── README.md # 本文件 ``` ## ev 模块 (Nginx WebSocket 长连接模块) ev 是核心网关模块,基于 Nginx 实现 WebSocket 长连接管理,提供: - **客户端管理**:红黑树存储,O(log n) 查找 - **后端转发**:Auth / Heartbeat / Proxy 三类消息统一经连接池转发 - **Redis 集成**:同步 SET/GET 键值操作 - **连接池管理**:HTTP/1.1 长连接复用 详细文档见 [ev/.agents/skills/AGENTS.md](ev/.agents/skills/AGENTS.md)。 ## Go 后端服务 | 控制器 | 路由 | 功能 | |--------|------|------| | `Auth` | `/auth/ws` | WebSocket 认证服务 | | `Heartbeat` | `/heartbeat/ws` | WebSocket 心跳服务 | | `Proxy` | `/proxy/ws` | WebSocket 代理转发服务 | | `Push` | `/push/send` | HTTP 消息推送接口 | ## 快速开始 ### 编译 Nginx ev 模块 ```bash wget http://nginx.org/download/nginx-1.20.2.tar.gz tar -zxvf nginx-1.20.2.tar.gz cd nginx-1.20.2 ./configure --add-module=/path/to/push/ev --with-http_ssl_module make && make install ``` ### Nginx 配置示例 ```nginx events { worker_connections 1024; } http { ev_max_message_size 65536; ev_default_heartbeat_interval 60; ev_ws_s_uuid "1E728118-5DAC-445B-9B7A-309678142C87"; ev_ws_c_uuid "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; ev_proxy { ev_proxy_enabled on; ev_proxy_server "https://127.0.0.1:8083/proxy"; ev_proxy_keepalive_enable on; ev_proxy_max_count 32; ev_proxy_reconnect_enable on; ev_proxy_queue 10000; } ev_push_ms { ev_push_ms_enabled on; ev_push_ms_server "127.0.0.1"; ev_push_ms_port 6379; ev_push_ms_password "your_password"; ev_push_ms_channel_index 0; } server { listen 1935; location /ws { ev_http; } } } ``` ## 技术栈 | 组件 | 版本 | 说明 | |------|------|------| | Nginx | 1.20+ | WebSocket 网关 | | Go | 1.21.10 | 后端服务语言 | | Redis | 6.0+ | 键值存储 | | OpenSSL | - | TLS/SSL 支持 | ## 通信协议 详见 [ev/protocol.md](ev/protocol.md)。 ## License MIT