{"id":13630961,"url":"https://github.com/crossoverJie/cim","last_synced_at":"2025-04-17T17:32:14.953Z","repository":{"id":37432535,"uuid":"134164777","full_name":"crossoverJie/cim","owner":"crossoverJie","description":"📲cim(cross IM) 适用于开发者的分布式即时通讯系统","archived":false,"fork":false,"pushed_at":"2024-11-20T09:47:50.000Z","size":34954,"stargazers_count":9393,"open_issues_count":39,"forks_count":2863,"subscribers_count":390,"default_branch":"master","last_synced_at":"2025-04-08T20:12:22.184Z","etag":null,"topics":["heartbeat","im","netty","tcp"],"latest_commit_sha":null,"homepage":"https://crossoverjie.top/categories/Netty/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crossoverJie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-20T15:55:56.000Z","updated_at":"2025-04-04T08:07:28.000Z","dependencies_parsed_at":"2024-09-20T10:01:20.689Z","dependency_job_id":"33b4551f-9a29-4576-8de5-cb3d112d9cfc","html_url":"https://github.com/crossoverJie/cim","commit_stats":{"total_commits":445,"total_committers":15,"mean_commits":"29.666666666666668","dds":0.3146067415730337,"last_synced_commit":"53dc4965642255d610965ae904158b514dbc3cc8"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crossoverJie%2Fcim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crossoverJie%2Fcim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crossoverJie%2Fcim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crossoverJie%2Fcim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crossoverJie","download_url":"https://codeload.github.com/crossoverJie/cim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249360046,"owners_count":21257162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["heartbeat","im","netty","tcp"],"created_at":"2024-08-01T22:02:04.734Z","updated_at":"2025-04-17T17:32:10.723Z","avatar_url":"https://github.com/crossoverJie.png","language":"Java","readme":"\n\n\u003cdiv align=\"center\"\u003e  \n\n\u003cimg src=\"https://i.loli.net/2020/02/21/rfOGvKlTcHCmM92.png\"  /\u003e \n\u003cbr/\u003e\n\n[![codecov](https://codecov.io/gh/crossoverJie/cim/graph/badge.svg?token=oW5Gd1oKmf)](https://codecov.io/gh/crossoverJie/cim)\n[![Build Status](https://img.shields.io/badge/cim-cross--im-brightgreen.svg)](https://github.com/crossoverJie/cim)\n[![](https://badge.juejin.im/entry/5c2c000e6fb9a049f5713e26/likes.svg?style=flat-square)](https://juejin.im/post/5c2bffdc51882509181395d7)\n\n📘[介绍](#介绍) |📽[视频演示](#视频演示) | 🏖[TODO LIST](#todo-list) | 🌈[系统架构](#系统架构) |💡[流程图](#流程图)|🌁[快速启动](#快速启动)|👨🏻‍✈️[内置命令](#客户端内置命令)|🎤[通信](#群聊私聊)|❓[QA](https://github.com/crossoverJie/cim/blob/master/doc/QA.md)|💌[联系作者](#联系作者)\n\n\n\u003c/div\u003e\n\u003cbr/\u003e\n\n# V2.0\n- [x] Upgrade to JDK17 \u0026 springboot3.0 \n- [x] Client SDK \n- [ ] Client use [picocli](https://picocli.info/) instead of springboot.\n- [x] Support integration testing.\n- [ ] Integrate OpenTelemetry .\n- [ ] Support single node startup(Contains no components).\n- [ ] Third-party components support replacement(Redis/Zookeeper, etc.).\n- [ ] Support web client(websocket).\n- [ ] Support docker container.\n- [ ] Support kubernetes operation.\n- [ ] Supports binary client(build with golang).\n\n## Introduction\n\n`CIM(CROSS-IM)` is an `IM (instant messaging)` system for developers; it also provides some components to help developers build their own scalable `IM`.\nUsing `CIM`, you can achieve the following requirements:\n- `IM` instant messaging system.\n- Message push middleware for `APP`.\n- Message middleware for `IOT` massive connection scenarios.\n\n\u003e If you have any questions during use or development, you can [contact me](#联系作者).\n\n## 视频演示\n\n\u003e 点击下方链接可以查看视频版 Demo。\n\n| YouTube | Bilibili|\n| :------:| :------: | \n| [群聊](https://youtu.be/_9a4lIkQ5_o) [私聊](https://youtu.be/kfEfQFPLBTQ) | [群聊](https://www.bilibili.com/video/av39405501) [私聊](https://www.bilibili.com/video/av39405821) | \n| \u003cimg src=\"https://i.loli.net//2019//05//08//5cd1d9e788004.jpg\"  height=\"295px\" /\u003e  | \u003cimg src=\"https://i.loli.net//2019//05//08//5cd1da2f943c5.jpg\" height=\"295px\" /\u003e\n\n![demo.gif](pic/demo.gif)\n\n## TODO LIST\n\n* [x] [群聊](#群聊)\n* [x] [私聊](#私聊)\n* [x] [内置命令](#客户端内置命令)\n* [x] [聊天记录查询](#聊天记录查询)。\n* [x] [一键开启价值 2 亿的 `AI` 模式](#ai-模式)\n* [x] 使用 `Google Protocol Buffer` 高效编解码\n* [x] 根据实际情况灵活的水平扩容、缩容\n* [x] 服务端自动剔除离线客户端\n* [x] 客户端自动重连\n* [x] [延时消息](#延时消息)\n* [x] SDK 开发包\n* [ ] 分组群聊\n* [ ] 离线消息\n* [ ] 消息加密\n\n\n\n## Architecture\n\n![](pic/architecture.png)\n\n- Each component in `CIM` is built using `SpringBoot`\n  - Client build with [cim-client-sdk](https://github.com/crossoverJie/cim/tree/master/cim-client-sdk)\n- Use `Netty` to build the underlying communication.\n- `MetaStore` is used for registration and discovery of `IM-server` services.\n\n\n### cim-server\nIM server is used to receive client connections, message forwarding, message push, etc.\nSupport cluster deployment.\n\n### cim-route\n\nRoute server; used to process message routing, message forwarding, user login, user offline, and some operation tools (get the number of online users, etc.).\n\n### cim-client\nIM client terminal, a command can be started and initiated to communicate with others (group chat, private chat).\n\n## Flow Chart\n\n![](https://s2.loli.net/2024/10/13/8teMn7BSa5VWuvi.png)\n\n- Server register to `MetaStore`\n- Route subscribe `MetaStore`\n- Client login to Route\n  - Route get Server info from `MetaStore`\n- Client open connection to Server\n- Client1 send message to Route\n- Route select Server and forward message to Server\n- Server push message to Client2\n\n\n## 快速启动\n\n首先需要安装 `Zookeeper、Redis` 并保证网络通畅。\n\n```shell\ndocker run --rm --name zookeeper -d -p 2181:2181 zookeeper:3.9.2\ndocker run --rm --name redis -d -p 6379:6379 redis:7.4.0\n```\n\n```shell\ngit clone https://github.com/crossoverJie/cim.git\ncd cim\nmvn clean package -DskipTests=true\ncd cim-server \u0026\u0026 cim-client \u0026\u0026 cim-forward-route\nmvn clean package spring-boot:repackage -DskipTests=true\n```\n\n### 部署 IM-server(cim-server)\n\n```shell\ncp /cim/cim-server/target/cim-server-1.0.0-SNAPSHOT.jar /xx/work/server0/\ncd /xx/work/server0/\nnohup java -jar  /root/work/server0/cim-server-1.0.0-SNAPSHOT.jar --cim.server.port=9000 --app.zk.addr=zk地址  \u003e /root/work/server0/log.file 2\u003e\u00261 \u0026\n```\n\n\u003e cim-server 集群部署同理，只要保证 Zookeeper 地址相同即可。\n\n### 部署路由服务器(cim-forward-route)\n\n```shell\ncp /cim/cim-server/cim-forward-route/target/cim-forward-route-1.0.0-SNAPSHOT.jar /xx/work/route0/\ncd /xx/work/route0/\nnohup 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  \u003e /root/work/route/log.file 2\u003e\u00261 \u0026\n```\n\n\u003e cim-forward-route 本身就是无状态，可以部署多台；使用 Nginx 代理即可。\n\n\n### 启动客户端\n\n```shell\ncp /cim/cim-client/target/cim-client-1.0.0-SNAPSHOT.jar /xx/work/route0/\ncd /xx/work/route0/\njava -jar cim-client-1.0.0-SNAPSHOT.jar --server.port=8084 --cim.user.id=唯一客户端ID --cim.user.userName=用户名 --cim.route.url=http://路由服务器:8083/\n```\n\n![](https://ws2.sinaimg.cn/large/006tNbRwly1fylgxjgshfj31vo04m7p9.jpg)\n![](https://ws1.sinaimg.cn/large/006tNbRwly1fylgxu0x4uj31hy04q75z.jpg)\n\n如上图，启动两个客户端可以互相通信即可。\n\n### 本地启动客户端\n\n#### 注册账号\n```shell\ncurl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{\n  \"reqNo\": \"1234567890\",\n  \"timeStamp\": 0,\n  \"userName\": \"zhangsan\"\n}' 'http://路由服务器:8083/registerAccount'\n```\n\n从返回结果中获取 `userId`\n\n```json\n{\n    \"code\":\"9000\",\n    \"message\":\"成功\",\n    \"reqNo\":null,\n    \"dataBody\":{\n        \"userId\":1547028929407,\n        \"userName\":\"test\"\n    }\n}\n```\n\n#### 启动本地客户端\n```shell\n# 启动本地客户端\ncp /cim/cim-client/target/cim-client-1.0.0-SNAPSHOT.jar /xx/work/route0/\ncd /xx/work/route0/\njava -jar cim-client-1.0.0-SNAPSHOT.jar --server.port=8084 --cim.user.id=上方返回的userId --cim.user.userName=用户名 --cim.route.url=http://路由服务器:8083/\n```\n\n## 客户端内置命令\n\n| 命令 | 描述|\n| ------ | ------ | \n| `:q!` | 退出客户端| \n| `:olu` | 获取所有在线用户信息 | \n| `:all` | 获取所有命令 | \n| `:q [option]` | 【:q 关键字】查询聊天记录 | \n| `:ai` | 开启 AI 模式 | \n| `:qai` | 关闭 AI 模式 | \n| `:pu` | 模糊匹配用户 | \n| `:info` | 获取客户端信息 | \n| `:emoji [option]` | 查询表情包 [option:页码] | \n| `:delay [msg] [delayTime]` | 发送延时消息 | \n| `:` | 更多命令正在开发中。。 | \n\n![](https://ws3.sinaimg.cn/large/006tNbRwly1fylh7bdlo6g30go01shdt.gif)\n\n### 聊天记录查询\n\n![](https://i.loli.net/2019/05/08/5cd1c310cb796.jpg)\n\n使用命令 `:q 关键字` 即可查询与个人相关的聊天记录。\n\n\u003e 客户端聊天记录默认存放在 `/opt/logs/cim/`，所以需要这个目录的写入权限。也可在启动命令中加入 `--cim.msg.logger.path = /自定义` 参数自定义目录。\n\n\n\n### AI 模式\n\n![](https://i.loli.net/2019/05/08/5cd1c30e47d95.jpg)\n\n使用命令 `:ai` 开启 AI 模式，之后所有的消息都会由 `AI` 响应。\n\n`:qai` 退出 AI 模式。\n\n### 前缀匹配用户名\n\n![](https://i.loli.net/2019/05/08/5cd1c32ac3397.jpg)\n\n使用命令 `:qu prefix` 可以按照前缀的方式搜索用户信息。\n\n\u003e 该功能主要用于在移动端中的输入框中搜索用户。 \n\n### 群聊/私聊\n\n#### 群聊\n\n![](https://ws1.sinaimg.cn/large/006tNbRwly1fyli54e8e1j31t0056x11.jpg)\n![](https://ws3.sinaimg.cn/large/006tNbRwly1fyli5yyspmj31im06atb8.jpg)\n![](https://ws3.sinaimg.cn/large/006tNbRwly1fyli6sn3c8j31ss06qmzq.jpg)\n\n群聊只需要在控制台里输入消息回车后即可发送，同时所有在线客户端都可收到消息。\n\n#### 私聊\n\n私聊首先需要知道对方的 `userID` 才能进行。\n\n输入命令 `:olu` 可列出所有在线用户。\n\n![](https://ws4.sinaimg.cn/large/006tNbRwly1fyli98mlf3j31ta06mwhv.jpg)\n\n接着使用 `userId;;消息内容` 的格式即可发送私聊消息。\n\n![](https://ws4.sinaimg.cn/large/006tNbRwly1fylib08qlnj31sk082zo6.jpg)\n![](https://ws1.sinaimg.cn/large/006tNbRwly1fylibc13etj31wa0564lp.jpg)\n![](https://ws3.sinaimg.cn/large/006tNbRwly1fylicmjj6cj31wg07c4qp.jpg)\n![](https://ws1.sinaimg.cn/large/006tNbRwly1fylicwhe04j31ua03ejsv.jpg)\n\n同时另一个账号收不到消息。\n![](https://ws3.sinaimg.cn/large/006tNbRwly1fylie727jaj31t20dq1ky.jpg)\n\n\n\n### emoji 表情支持\n\n使用命令 `:emoji 1` 查询出所有表情列表，使用表情别名即可发送表情。\n\n![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6j910cqrzj30dn05qjw9.jpg)\n![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6j99hazg6j30ax03hq35.jpg)\n \n### 延时消息\n\n发送 10s 的延时消息：\n\n```shell\n:delay delayMsg 10\n```\n\n![](pic/delay.gif)\n\n## 联系作者\n\n\u003cdiv align=\"center\"\u003e  \n\n\u003ca href=\"https://t.zsxq.com/odQDJ\" target=\"_blank\"\u003e\u003cimg src=\"https://s2.loli.net/2024/05/17/zRkabDu2SKfChLX.png\" alt=\"202405171520366.png\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n最近开通了知识星球，感谢大家对 CIM 的支持，为大家提供 100 份 10 元优惠券，也就是 69-10=59 元，具体福利大家可以扫码参考再决定是否加入。\n\n\u003e PS: 后续会在星球开始 V2.0 版本的重构，感兴趣的可以加入星球当面催更（当然代码依然会开源）。\n\n- [crossoverJie@gmail.com](mailto:crossoverJie@gmail.com)\n- 微信公众号\n\n![index.jpg](https://i.loli.net/2021/10/12/ckQW9LYXSxFogJZ.jpg)\n\n\n\n","funding_links":[],"categories":["Java","网络信息服务","Web Development","网络编程"],"sub_categories":["信息沟通","C++/C Toolkit","Spring Cloud框架"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcrossoverJie%2Fcim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FcrossoverJie%2Fcim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcrossoverJie%2Fcim/lists"}