Build Your Own Scalable Developer‑Focused IM System with CIM: A Step‑by‑Step Guide
This article introduces CIM, a developer‑oriented distributed instant messaging platform, outlines its current features and roadmap, explains its SpringBoot‑Netty‑Redis‑Zookeeper architecture, and provides detailed installation, configuration, and usage instructions with code examples.
Ever wondered how to create a developer‑friendly distributed instant messaging system? CIM (Cross IM) is an open‑source IM solution designed for developers, offering components to build a custom chat tool.
Implemented features include group chat, private chat, built‑in commands, chat history search, one‑click AI mode, efficient encoding with Google Protocol Buffer, flexible horizontal scaling, automatic removal of offline clients, client auto‑reconnect, and delayed messages.
Group chat
Private chat
Built‑in commands
Chat history query
AI mode
Google Protocol Buffer encoding
Dynamic scaling
Server auto‑prunes offline clients
Client auto‑reconnect
Delayed messages
Planned enhancements are group chat segmentation, SDK packages, offline messaging, and encrypted protocol support.
The overall system architecture is illustrated below:
Each component is built with SpringBoot; Netty handles low‑level communication, Redis stores routing, account, and online status data, and Zookeeper provides IM‑server registration and discovery.
The functional flow works as follows: the client logs in via the route service, receives an available IM‑server address from Zookeeper, stores login and routing info in Redis, establishes a long‑lived connection to the IM‑server, and clears state on logout.
Quick start in four steps:
1. Install Zookeeper and Redis and ensure network connectivity.
cd cim
mvn -Dmaven.test.skip=true clean package2. Deploy the IM‑server (cim‑server). Deploy multiple instances with the same Zookeeper address.
cp /cim/cim-server/target/cim-server-1.0.0-SNAPSHOT.jar /xx/work/server0/
cd /xx/work/server0/
nohup java -jar /root/work/server0/cim-server-1.0.0-SNAPSHOT.jar --cim.server.port=9000 --app.zk.addr=zk_address > /root/work/server0/log.file 2>&1 &3. Deploy the routing server (cim‑forward‑route). It is stateless and can be scaled; use Nginx as a proxy.
cp /cim/cim-server/cim-forward-route/target/cim-forward-route-1.0.0-SNAPSHOT.jar /xx/work/route0/
cd /xx/work/route0/
nohup java -jar /root/work/route0/cim-forward-route-1.0.0-SNAPSHOT.jar --app.zk.addr=zk_address --spring.redis.host=redis_address --spring.redis.port=6379 > /root/work/route/log.file 2>&1 &4. Start two client instances to communicate.
cp /cim/cim-client/target/cim-client-1.0.0-SNAPSHOT.jar /xx/work/route0/
cd /xx/work/route0/
java -jar cim-client-1.0.0-SNAPSHOT.jar --server.port=8084 --cim.user.id=unique_client_id --cim.user.userName=username --cim.route.url=http://router_server:8083/Common built‑in client commands: :q! – exit client :olu – list online users :all – list all commands :q [option] – query chat history :ai – enable AI mode :qai – disable AI mode :pu – fuzzy user matching :info – get client info :emoji [option] – browse emojis :delay [msg] [delayTime] – send delayed message
Sample chat sessions demonstrate the system’s capabilities:
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
