cim
📲cim(cross IM) 适用于开发者的分布式即时通讯系统
An open-source instant messaging system built for developers to study or extend, supports group and private chat out of the box, designed to scale across multiple servers.
CIM (Cross-IM) is an instant messaging system built for developers who want to add real-time chat to their own applications, or who want to study how a scalable messaging system is put together. It supports group chat and private chat out of the box, and its architecture is designed to be extended or deployed across multiple servers if traffic grows.
The system is split into three main pieces. There is a server component that holds open connections from all chat clients. There is a routing server that figures out which messages go to which users and handles login, logout, and user lookups. And there is a client component that end users run from a command line to send and receive messages. The routing layer acts as the coordinator: when one client sends a message, the route server finds the right server node and forwards the message to the recipient.
For storage and coordination, CIM relies on Zookeeper (used so that multiple server nodes can discover each other and stay in sync) and Redis (used for caching user and session data). The easiest way to get started is a Docker image called "allin1" that bundles all of these components together, so you can run the whole system with a single command and two port mappings.
Built-in features include delayed messages, chat history search, client auto-reconnection when a connection drops, and an AI mode (the README references this without going into detail). The client interface is command-line based and has a small set of slash commands for things like listing online users, switching to private chat, and searching message history.
The project is written in Java using Spring Boot and Netty, a library for building network servers. It requires Java 17 and has been updated to Spring Boot 3. Items still on the roadmap include offline message delivery, message encryption, web browser support via WebSocket, and the option to run without external dependencies like Zookeeper.
Where it fits
- Run a self-hosted real-time chat server using a single Docker command and connect command-line clients immediately.
- Study how a scalable instant messaging system handles routing and session management by reading the source code.
- Add real-time messaging to your own Java application by extending the CIM codebase.