|
@@ -0,0 +1,74 @@
|
|
|
|
|
+# message-server
|
|
|
|
|
+
|
|
|
|
|
+### 现有功能
|
|
|
|
|
+- **多房间聊天室**: 通过 `/room?room=<房间名>` 动态创建/加入房间,彼此隔离。
|
|
|
|
|
+- **实时消息广播**: 同一房间内消息通过 WebSocket 即时分发。
|
|
|
|
|
+- **昵称**: 连接时为生成 clientName (门店端: shop_{shopId}_{staffId}, 买家端: customer_{customId}_{userId}), 用于生成客户端的唯一标识,用作唯一标识,进行查找用的
|
|
|
|
|
+
|
|
|
|
|
+### 易于扩展的功能(建议优先级)
|
|
|
|
|
+- **加入/离开通知与在线人数**: 日志记录--用户进入/离开,统计当前在线数。
|
|
|
|
|
+- **房间列表与切换**: 展示活跃房间、快速切换/创建。
|
|
|
|
|
+- **用户自定义昵称**: 支持登录前设置昵称,校验重复。
|
|
|
|
|
+- **私聊与@提醒**: 支持点对点消息、@用户名提醒。
|
|
|
|
|
+- **权限与房间控制**: 房间密码/邀请制、人数上限、管理员踢人/禁言。
|
|
|
|
|
+- **防刷与限流**: 消息频率限制、黑名单、基础审核。
|
|
|
|
|
+- **富文本/附件**: 表情、Markdown、图片/文件上传(结合后端存储)。
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+## 服务上线
|
|
|
|
|
+
|
|
|
|
|
+### 1. 配置 nginx
|
|
|
|
|
+创建Nginx WebSocket 配置文件。参考测试环境的 nginx conf 文件 -- chat.shop.huaml.com.conf
|
|
|
|
|
+```
|
|
|
|
|
+server {
|
|
|
|
|
+ listen 443 ssl;
|
|
|
|
|
+ server_name chat.shop.huaml.com;
|
|
|
|
|
+
|
|
|
|
|
+ ssl_certificate /usr/local/nginx/cert/webSocket/chat.shop.huaml.com.pem;
|
|
|
|
|
+ ssl_certificate_key /usr/local/nginx/cert/webSocket/chat.shop.huaml.com.key;
|
|
|
|
|
+
|
|
|
|
|
+ location / {
|
|
|
|
|
+ proxy_pass http://127.0.0.1:8080;
|
|
|
|
|
+ proxy_http_version 1.1;
|
|
|
|
|
+ proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
+ proxy_set_header Connection "Upgrade";
|
|
|
|
|
+ proxy_set_header Host $host;
|
|
|
|
|
+ proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
+ proxy_read_timeout 120s; # 读超时(客户端多久没发消息就断开)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+```
|
|
|
|
|
+
|
|
|
|
|
+### 编译
|
|
|
|
|
+1. 摘取代码,执行:`go build main.go`
|
|
|
|
|
+ - 要安装 go , 不想安装,那直接在测试服务编译,然后下载下来。
|
|
|
|
|
+ - 代码库:http://git.huaml.com/shizhongqi/message-server
|
|
|
|
|
+
|
|
|
|
|
+2. 把生成的 main 文件放到线上,并配置好 .env 文件
|
|
|
|
|
+```
|
|
|
|
|
+LOG_MODE=color
|
|
|
|
|
+LOG_LEVEL=0
|
|
|
|
|
+
|
|
|
|
|
+REDIS_ADDR=118.178.193.23:6379
|
|
|
|
|
+REDIS_PASSWORD=byt6gc1w0aed2q7h
|
|
|
|
|
+REDIS_DB=0
|
|
|
|
|
+
|
|
|
|
|
+SERVER_ADDR=:8080
|
|
|
|
|
+
|
|
|
|
|
+HUA_ZHANG_GUI_URL=https://api.shop.huahb.cn
|
|
|
|
|
+HUA_HUI_BAO_URL=https://api.shop.zhiguanhua.cn
|
|
|
|
|
+```
|
|
|
|
|
+要把对应配置项改为线上的
|
|
|
|
|
+
|
|
|
|
|
+3. 后台运行(简单方法)
|
|
|
|
|
+ 使用 `nohup` 或 `&`:
|
|
|
|
|
+ ```
|
|
|
|
|
+ nohup ./main > ./message_server.log 2>&1 &
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+ 查看进程:
|
|
|
|
|
+ ```
|
|
|
|
|
+ ps -ef | grep main
|
|
|
|
|
+ ```
|