Skip to content

Commit 5a5df5c

Browse files
committed
docs: add Chinese README for improved accessibility and user guidance
1 parent 9e56b0f commit 5a5df5c

1 file changed

Lines changed: 360 additions & 0 deletions

File tree

README-zh.md

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
2+
3+
4+
<div align="center">
5+
6+
<img src="https://i.loli.net/2020/02/21/rfOGvKlTcHCmM92.png" />
7+
<br/>
8+
9+
[![codecov](https://codecov.io/gh/crossoverJie/cim/graph/badge.svg?token=oW5Gd1oKmf)](https://codecov.io/gh/crossoverJie/cim)
10+
[![Build Status](https://img.shields.io/badge/cim-cross--im-brightgreen.svg)](https://github.com/crossoverJie/cim)
11+
[![](https://badge.juejin.im/entry/5c2c000e6fb9a049f5713e26/likes.svg?style=flat-square)](https://juejin.im/post/5c2bffdc51882509181395d7)
12+
13+
📘[介绍](#介绍) |📽[视频演示](#视频演示) | 🏖[TODO LIST](#todo-list) | 🌈[系统架构](#系统架构) |💡[流程图](#流程图)|🌁[快速启动](#快速启动)|👨🏻‍✈️[内置命令](#客户端内置命令)|🎤[通信](#群聊私聊)|❓[QA](https://github.com/crossoverJie/cim/blob/master/doc/QA.md)|💌[联系作者](#联系作者)
14+
15+
[English](README.md)
16+
17+
</div>
18+
<br/>
19+
20+
# V2.0
21+
- [x] 升级至 JDK17 & springboot3.0
22+
- [x] Client SDK
23+
- [ ] 客户端使用 [picocli](https://picocli.info/) 替代 springboot
24+
- [x] 支持集成测试
25+
- [ ] 集成 OpenTelemetry
26+
- [ ] 支持单节点启动(不依赖外部组件)
27+
- [ ] 第三方组件支持替换(Redis/Zookeeper 等)
28+
- [ ] 支持 Web 客户端(websocket)
29+
- [x] 支持 Docker 容器
30+
- [ ] 支持 Kubernetes 部署
31+
- [ ] 支持二进制客户端(使用 golang 构建)
32+
33+
## 介绍
34+
35+
`CIM(CROSS-IM)` 是面向开发者的 `IM(即时通讯)` 系统;同时提供了一些组件帮助开发者构建自己可扩展的 `IM`
36+
借助 `CIM` 你可以实现以下需求:
37+
- `IM` 即时通讯系统。
38+
- `APP` 消息推送中间件。
39+
- `IOT` 海量连接场景中的消息中间件。
40+
41+
> 如果在使用或开发过程中有任何问题,可以[联系作者](#联系作者)
42+
43+
## 视频演示
44+
45+
> 点击下方链接可以查看视频版 Demo。
46+
47+
| YouTube | Bilibili|
48+
| :------:| :------: |
49+
| [群聊](https://youtu.be/_9a4lIkQ5_o) [私聊](https://youtu.be/kfEfQFPLBTQ) | [群聊](https://www.bilibili.com/video/av39405501) [私聊](https://www.bilibili.com/video/av39405821) |
50+
| <img src="https://i.loli.net//2019//05//08//5cd1d9e788004.jpg" height="295px" /> | <img src="https://i.loli.net//2019//05//08//5cd1da2f943c5.jpg" height="295px" />
51+
52+
![demo.gif](pic/demo.gif)
53+
54+
## TODO LIST
55+
56+
* [x] [群聊](#群聊)
57+
* [x] [私聊](#私聊)
58+
* [x] [内置命令](#客户端内置命令)
59+
* [x] [聊天记录查询](#聊天记录查询)
60+
* [x] [一键开启 AI 模式](#ai-模式)
61+
* [x] 使用 `Google Protocol Buffer` 高效编解码
62+
* [x] 根据实际情况灵活的水平扩容、缩容
63+
* [x] 服务端自动剔除离线客户端
64+
* [x] 客户端自动重连
65+
* [x] [延时消息](#延时消息)
66+
* [x] SDK 开发包
67+
* [ ] 分组群聊
68+
* [ ] 离线消息
69+
* [ ] 消息加密
70+
71+
72+
73+
## 系统架构
74+
75+
![](pic/architecture.png)
76+
77+
- `CIM` 中的各个组件均采用 `SpringBoot` 构建
78+
- 客户端基于 [cim-client-sdk](https://github.com/crossoverJie/cim/tree/master/cim-client-sdk) 构建
79+
- 采用 `Netty` 构建底层通信
80+
- `MetaStore` 用于 `IM-server` 服务的注册与发现
81+
82+
83+
### cim-server
84+
IM 服务端,用于接收客户端连接、消息转发、消息推送等功能。
85+
支持集群部署。
86+
87+
### cim-route
88+
89+
路由服务器;用于处理消息路由、消息转发、用户登录、用户下线以及一些运维工具(获取在线用户数等)。
90+
91+
### cim-client
92+
IM 客户端终端,一个命令即可启动并与其他人进行通信(群聊、私聊)。
93+
94+
## 流程图
95+
96+
![](https://s2.loli.net/2024/10/13/8teMn7BSa5VWuvi.png)
97+
98+
- Server 注册到 `MetaStore`
99+
- Route 订阅 `MetaStore`
100+
- Client 登录到 Route
101+
- Route 从 `MetaStore` 获取 Server 信息
102+
- Client 与 Server 建立连接
103+
- Client1 发送消息到 Route
104+
- Route 选择 Server 并将消息转发给 Server
105+
- Server 将消息推送给 Client2
106+
107+
108+
## 快速启动
109+
110+
### Docker
111+
112+
`allin1` 镜像内置了 Zookeeper、Redis、cim-server、cim-forward-route 四个服务,使用 [Supervisor](http://supervisord.org/) 统一管理,开箱即用。
113+
114+
**支持平台:** linux/amd64, linux/arm64, linux/arm/v7
115+
116+
**端口说明:**
117+
118+
| 端口 | 服务 | 说明 |
119+
|------|---------|-------------|
120+
| 2181 | Zookeeper | 服务注册与发现 |
121+
| 6379 | Redis | 数据缓存 |
122+
| 8083 | Route Server | HTTP API 路由服务 |
123+
124+
拉取镜像并启动:
125+
126+
```shell
127+
docker pull ghcr.io/crossoverjie/allin1-ubuntu:latest
128+
docker run -p 2181:2181 -p 6379:6379 -p 8083:8083 --rm --name cim-allin1 ghcr.io/crossoverjie/allin1-ubuntu:latest
129+
```
130+
131+
容器启动后,可参考下方 [注册账号](#注册账号)[启动客户端](#启动客户端) 章节快速体验完整的 IM 流程。
132+
133+
### 本地构建 Docker 镜像
134+
135+
如果需要从源码构建镜像:
136+
137+
```shell
138+
# 在项目根目录执行
139+
docker build -t cim-allin1:latest -f docker/allin1-ubuntu.Dockerfile .
140+
docker run -p 2181:2181 -p 6379:6379 -p 8083:8083 --rm --name cim-allin1 cim-allin1:latest
141+
```
142+
143+
### 本地编译
144+
145+
首先需要安装 `Zookeeper``Redis` 并保证网络通畅。
146+
147+
```shell
148+
docker run --rm --name zookeeper -d -p 2181:2181 zookeeper:3.9.2
149+
docker run --rm --name redis -d -p 6379:6379 redis:7.4.0
150+
```
151+
152+
```shell
153+
git clone https://github.com/crossoverJie/cim.git
154+
cd cim
155+
mvn clean install -DskipTests=true
156+
cd cim-server && cim-client && cim-forward-route
157+
mvn clean package spring-boot:repackage -DskipTests=true
158+
```
159+
160+
### 部署 IM-server(cim-server)
161+
162+
```shell
163+
cp /cim/cim-server/target/cim-server-1.0.0-SNAPSHOT.jar /xx/work/server0/
164+
cd /xx/work/server0/
165+
nohup java -jar /root/work/server0/cim-server-1.0.0-SNAPSHOT.jar --cim.server.port=9000 --app.zk.addr=zk地址 > /root/work/server0/log.file 2>&1 &
166+
```
167+
168+
> cim-server 集群部署同理,只要保证 Zookeeper 地址相同即可。
169+
170+
### 部署路由服务器(cim-forward-route)
171+
172+
```shell
173+
cp /cim/cim-server/cim-forward-route/target/cim-forward-route-1.0.0-SNAPSHOT.jar /xx/work/route0/
174+
cd /xx/work/route0/
175+
nohup java -jar /root/work/route0/cim-forward-route-1.0.0-SNAPSHOT.jar --app.zk.addr=zk地址 --spring.redis.host=redis地址 --spring.redis.port=6379 > /root/work/route/log.file 2>&1 &
176+
```
177+
178+
> cim-forward-route 本身就是无状态,可以部署多台;使用 Nginx 代理即可。
179+
180+
181+
### 启动客户端
182+
183+
```shell
184+
cp /cim/cim-client/target/cim-client-1.0.0-SNAPSHOT.jar /xx/work/route0/
185+
cd /xx/work/route0/
186+
java -jar cim-client-1.0.0-SNAPSHOT.jar --server.port=8084 --cim.user.id=唯一客户端ID --cim.user.userName=用户名 --cim.route.url=http://路由服务器:8083/
187+
```
188+
189+
![](https://ws2.sinaimg.cn/large/006tNbRwly1fylgxjgshfj31vo04m7p9.jpg)
190+
![](https://ws1.sinaimg.cn/large/006tNbRwly1fylgxu0x4uj31hy04q75z.jpg)
191+
192+
如上图,启动两个客户端可以互相通信即可。
193+
194+
### 本地启动客户端
195+
196+
#### 注册账号
197+
```shell
198+
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
199+
"reqNo": "1234567890",
200+
"timeStamp": 0,
201+
"userName": "zhangsan"
202+
}' 'http://路由服务器:8083/registerAccount'
203+
```
204+
205+
从返回结果中获取 `userId`
206+
207+
```json
208+
{
209+
"code":"9000",
210+
"message":"成功",
211+
"reqNo":null,
212+
"dataBody":{
213+
"userId":1547028929407,
214+
"userName":"test"
215+
}
216+
}
217+
```
218+
219+
#### 启动本地客户端
220+
```shell
221+
# 启动本地客户端
222+
cp /cim/cim-client/target/cim-client-1.0.0-SNAPSHOT.jar /xx/work/route0/
223+
cd /xx/work/route0/
224+
java -jar cim-client-1.0.0-SNAPSHOT.jar --server.port=8084 --cim.user.id=上方返回的userId --cim.user.userName=用户名 --cim.route.url=http://路由服务器:8083/
225+
```
226+
227+
## 客户端内置命令
228+
229+
| 命令 | 描述|
230+
| ------ | ------ |
231+
| `:q!` | 退出客户端|
232+
| `:olu` | 获取所有在线用户信息 |
233+
| `:all` | 获取所有命令 |
234+
| `:q [option]` |:q 关键字】查询聊天记录 |
235+
| `:ai` | 开启 AI 模式 |
236+
| `:qai` | 关闭 AI 模式 |
237+
| `:pu` | 模糊匹配用户 |
238+
| `:info` | 获取客户端信息 |
239+
| `:emoji [option]` | 查询表情包 [option:页码] |
240+
| `:delay [msg] [delayTime]` | 发送延时消息 |
241+
| `:` | 更多命令正在开发中。。 |
242+
243+
![](https://ws3.sinaimg.cn/large/006tNbRwly1fylh7bdlo6g30go01shdt.gif)
244+
245+
### 聊天记录查询
246+
247+
![](https://i.loli.net/2019/05/08/5cd1c310cb796.jpg)
248+
249+
使用命令 `:q 关键字` 即可查询与个人相关的聊天记录。
250+
251+
> 客户端聊天记录默认存放在 `/opt/logs/cim/`,所以需要这个目录的写入权限。也可在启动命令中加入 `--cim.msg.logger.path = /自定义` 参数自定义目录。
252+
253+
254+
255+
### AI 模式
256+
257+
![](https://i.loli.net/2019/05/08/5cd1c30e47d95.jpg)
258+
259+
使用命令 `:ai` 开启 AI 模式,之后所有的消息都会由 `AI` 响应。
260+
261+
`:qai` 退出 AI 模式。
262+
263+
### 前缀匹配用户名
264+
265+
![](https://i.loli.net/2019/05/08/5cd1c32ac3397.jpg)
266+
267+
使用命令 `:qu prefix` 可以按照前缀的方式搜索用户信息。
268+
269+
> 该功能主要用于在移动端中的输入框中搜索用户。
270+
271+
### 群聊/私聊
272+
273+
#### 群聊
274+
275+
![](https://ws1.sinaimg.cn/large/006tNbRwly1fyli54e8e1j31t0056x11.jpg)
276+
![](https://ws3.sinaimg.cn/large/006tNbRwly1fyli5yyspmj31im06atb8.jpg)
277+
![](https://ws3.sinaimg.cn/large/006tNbRwly1fyli6sn3c8j31ss06qmzq.jpg)
278+
279+
群聊只需要在控制台里输入消息回车后即可发送,同时所有在线客户端都可收到消息。
280+
281+
#### 私聊
282+
283+
私聊首先需要知道对方的 `userID` 才能进行。
284+
285+
输入命令 `:olu` 可列出所有在线用户。
286+
287+
![](https://ws4.sinaimg.cn/large/006tNbRwly1fyli98mlf3j31ta06mwhv.jpg)
288+
289+
接着使用 `userId;;消息内容` 的格式即可发送私聊消息。
290+
291+
![](https://ws4.sinaimg.cn/large/006tNbRwly1fylib08qlnj31sk082zo6.jpg)
292+
![](https://ws1.sinaimg.cn/large/006tNbRwly1fylibc13etj31wa0564lp.jpg)
293+
![](https://ws3.sinaimg.cn/large/006tNbRwly1fylicmjj6cj31wg07c4qp.jpg)
294+
![](https://ws1.sinaimg.cn/large/006tNbRwly1fylicwhe04j31ua03ejsv.jpg)
295+
296+
同时另一个账号收不到消息。
297+
![](https://ws3.sinaimg.cn/large/006tNbRwly1fylie727jaj31t20dq1ky.jpg)
298+
299+
300+
301+
### emoji 表情支持
302+
303+
使用命令 `:emoji 1` 查询出所有表情列表,使用表情别名即可发送表情。
304+
305+
![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6j910cqrzj30dn05qjw9.jpg)
306+
![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6j99hazg6j30ax03hq35.jpg)
307+
308+
### 延时消息
309+
310+
发送 10s 的延时消息:
311+
312+
```shell
313+
:delay delayMsg 10
314+
```
315+
316+
![](pic/delay.gif)
317+
318+
## 联系作者
319+
320+
## 贡献指南
321+
322+
欢迎贡献代码!提交 PR 前,请确保代码通过 Checkstyle 检查。
323+
324+
### 代码风格
325+
326+
本项目使用 [Checkstyle](https://checkstyle.org/) 来规范代码风格,规则定义在 `checkstyle/checkstyle.xml` 中。
327+
328+
**提交前在本地运行 Checkstyle:**
329+
330+
```shell
331+
mvn checkstyle:check
332+
```
333+
334+
**主要规则:**
335+
- `{``}` 和运算符前后使用空格
336+
- 行尾不能有空格
337+
- 文件必须以换行符结尾
338+
- 删除未使用的 import
339+
- 常量(`static final`)必须使用 `UPPER_SNAKE_CASE` 命名
340+
- 使用 Java 风格的数组声明:`String[] args`(而非 `String args[]`
341+
342+
**快速构建时跳过 Checkstyle:**
343+
344+
```shell
345+
mvn package -Dcheckstyle.skip=true
346+
```
347+
348+
<div align="center">
349+
350+
<a href="https://t.zsxq.com/odQDJ" target="_blank"><img src="https://s2.loli.net/2024/05/17/zRkabDu2SKfChLX.png" alt="202405171520366.png"></a>
351+
</div>
352+
353+
最近开通了知识星球,感谢大家对 CIM 的支持,为大家提供 100 份 10 元优惠券,也就是 69-10=59 元,具体福利大家可以扫码参考再决定是否加入。
354+
355+
> PS: 后续会在星球开始 V2.0 版本的重构,感兴趣的可以加入星球当面催更(当然代码依然会开源)。
356+
357+
- [crossoverJie@gmail.com](mailto:crossoverJie@gmail.com)
358+
- 微信公众号
359+
360+
![index.jpg](https://i.loli.net/2021/10/12/ckQW9LYXSxFogJZ.jpg)

0 commit comments

Comments
 (0)