# echo-im **Repository Path**: brother-one/echo-im ## Basic Information - **Project Name**: echo-im - **Description**: 一个IM(即时通讯)项目的后端系统。支持IM系统核心功能:好友、私聊、群聊、离线消息、发送语音、图片、文件、emoji表情、回执消息、视频聊天等 严格遵循IM系统的四大原则:实时性、幂等性、不丢失、时序性。 主要基于 Spring Boot 和 Netty 开发 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: https://gitee.com/brother-one/echo-im - **GVP Project**: No ## Statistics - **Stars**: 193 - **Forks**: 44 - **Created**: 2024-08-12 - **Last Updated**: 2026-04-11 ## Categories & Tags **Categories**: im **Tags**: SpringBoot, Netty, WebSocket, RabbitMQ, IM ## README

logo

Echo IM 1.2.0

High-Performance Instant Messaging System based on SpringBoot + Netty

[简体中文](README.md) | **English** --- ## 📋 Introduction Echo IM is a **production-grade** instant messaging system using microservices architecture and DDD design, strictly following the four core IM principles (real-time, no loss, idempotency, ordering). **Key Features**: - ✅ Multiple message brokers (RabbitMQ/Redis/RocketMQ switchable) - ✅ Decentralized message push, no single point of failure - ✅ Dual storage for offline messages (Redis + MySQL) - ✅ Application-level ACK + MQ task compensation - ✅ Flyway database version management - ✅ Vue3 + TypeScript frontend **Use Cases**: IM system learning, graduation projects, resume enhancement, secondary development --- ## 🚀 Quick Start ### Requirements | Component | Version | |-----------|---------| | JDK | 17+ | | Maven | 3.6+ | | MySQL | 8.0+ | | Redis | 6.0+ | | RabbitMQ | 3.x (or Redis/RocketMQ) | | Nginx | Latest (required for production) | ### One-Click Start with Docker Compose ```bash cd doc/dev-ops docker-compose -f docker-compose-enviroment.yml up -d ``` Services started: - MySQL: `localhost:3306` (root/test123456) - Redis: `localhost:6379` - RabbitMQ: `localhost:5672` (guest/guest) - RabbitMQ Management: http://localhost:15672 ### Configuration **1. Database Initialization** v1.2.0 uses Flyway for automatic migration. First startup will create all tables and indexes automatically. **2. Core Configuration (application-dev.yml)** ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/echo_im username: root password: test123456 data: redis: host: 127.0.0.1 port: 6379 rabbitmq: host: 127.0.0.1 port: 5672 username: guest password: guest # Message broker selection (rabbitmq/redis/rocketmq/load-balanced) im: message-broker: type: rabbitmq # Single broker for dev environment ``` ### Start Services **Development (IntelliJ IDEA)**: ``` 1. im-engin-server -> ImEnginServerApplication 2. im-platform-server -> ImPlatformServerApplication 3. im-storage-server -> ImStorageServerApplication ``` **Production (JAR)**: ```bash # Build mvn clean package -DskipTests # Start nohup java -jar im-engin-server/target/im-engin-server.jar & nohup java -jar im-platform-server/target/im-platform-server.jar & nohup java -jar im-storage-server/target/im-storage-server.jar & ``` ### Nginx Load Balancing **Why Nginx?** Frontend needs WebSocket connection. Nginx provides load balancing for multiple im-engin-server instances. **Configuration Example**: ```nginx # WebSocket load balancing (ip_hash for session persistence) upstream websocket_backend { ip_hash; server 127.0.0.1:9091; server 127.0.0.1:9092; server 127.0.0.1:9093; } # HTTP API load balancing upstream api_backend { server 127.0.0.1:8080; server 127.0.0.1:8180; } server { listen 80; server_name im.example.com; # WebSocket proxy location /ws { proxy_pass http://websocket_backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } # HTTP API proxy location /api/ { proxy_pass http://api_backend/; } } ``` **Full Configuration**: See `doc/nginx/echo-im.conf` **Frontend Configuration**: ```typescript // Production environment via Nginx const wsUrl = 'wss://im.example.com/ws'; const apiUrl = 'https://im.example.com/api'; ``` ### Verify Deployment ```bash # 1. Check service ports lsof -i:8080,8081,9091 # 2. API documentation curl http://localhost:8080/doc.html # 3. Register test user curl -X POST http://localhost:8080/auth/register \ -H "Content-Type: application/json" \ -d '{"username":"test","password":"123456"}' # 4. WebSocket connection test # Browser: http://www.websocket-test.com/ # URL: ws://localhost:9091/ws ``` --- ## 📖 Core Features ### IM Four Principles Implementation | Principle | Implementation | |-----------|----------------| | **Real-time** | Netty NIO + WebSocket + RabbitMQ async | | **No Loss** | App-level ACK + Dual storage + MQ compensation | | **Idempotency** | Client SEQ + Server MsgId | | **Ordering** | Snowflake MsgId + SEQ local order | ### Feature List - ✅ **Multi-device Login**: Same user on multiple devices - ✅ **Message Types**: Text, image, voice, file, video, emoji - ✅ **Message Features**: Offline, history, recall, read receipts - ✅ **Friend Management**: Add, delete, remark, online status - ✅ **Group Features**: Create, dissolve, invite, remove, @ mention - ✅ **File Storage**: MinIO object storage - ✅ **Multi-broker**: RabbitMQ/Redis/RocketMQ switchable --- ## 🔌 Tech Stack ### Backend | Technology | Version | Description | |------------|---------|-------------| | Spring Boot | 3.3.1 | Microservices framework | | Netty | - | High-performance networking | | MySQL | 8.0+ | Database | | Redis | 6.0+ | Cache + user status | | RabbitMQ | 3.x | Message queue (switchable) | | Flyway | 10.10.0 | Database migration | | Sa-Token | 1.38.0 | Authentication | | MinIO | 8.5.1 | Object storage | | MyBatis-Plus | 3.5.7 | ORM framework | ### Frontend | Technology | Version | Description | |------------|---------|-------------| | Vue | 3.x | Progressive framework | | TypeScript | 5.x | Type safety | | Vite | 5.x | Build tool | | Element Plus | 2.x | UI components | | Pinia | 2.x | State management | --- ## 🏗️ Architecture ### Overall Architecture ``` ┌─────────────┐ │ Nginx │ Load balancing + Reverse proxy └──────┬──────┘ │ ┌──────┴──────────────────────────────┐ │ │ │ ┌─────────────┐ ┌──────────────┐ │ │ │ im-platform │ │ im-engin │ │ │ │ (8080) │ │ (9091) │ │ │ └──────┬──────┘ └──────┬───────┘ │ │ │ │ │ │ └────────┬───────┘ │ │ │ │ │ ┌───────────────▼──────────────┐ │ │ │ RabbitMQ / Redis / RocketMQ│ │ │ └───────────────┬──────────────┘ │ │ │ │ │ ┌───────────────▼──────────────┐ │ │ │ im-storage (8082) │ │ │ └──────────────────────────────┘ │ └─────────────────────────────────────┘ │ ┌──────┴──────┐ │ │ ┌───▼───┐ ┌────▼────┐ │ MySQL │ │ Redis │ └───────┘ └─────────┘ ``` ### Multi-Broker Architecture **Core Design**: Each im-engin-server connects to ONE broker. im-platform-server routes intelligently based on serverId. ``` im-engin-server-1 → RabbitMQ im-engin-server-2 → Redis im-engin-server-3 → RocketMQ im-platform-server → LoadBalancer → Route to corresponding broker ``` **Load Balancing Strategies**: - **round-robin**: Round robin - **random**: Random selection - **weighted**: Weighted distribution - **hash**: Hash-based (recommended, ensures same serverId routes to same broker) --- ## 📂 Project Structure ``` echo-im/ ├── im-common/ # Common module ├── im-repository/ # Repository module ├── im-infrastructure/ # Infrastructure (Redis, MQ, MinIO) │ └── mq/ # Message broker abstraction │ ├── MessageBroker.java # Unified interface │ ├── impl/ │ │ ├── RabbitMQMessageBroker.java │ │ ├── RedisMessageBroker.java │ │ └── RocketMQMessageBroker.java │ └── strategy/ # Load balancing strategies ├── im-domain/ # Domain module ├── im-client-starter/ # Client SDK ├── im-engin-server/ # Message engine (Netty + WebSocket) ├── im-platform-server/ # Platform service (HTTP API) ├── im-storage-server/ # Storage service ├── im-offline-notify-server/ # Offline notification ├── echo-im-web/ # Vue3 frontend └── doc/ ├── nginx/ # Nginx configuration └── md/ # Documentation ``` --- ## 📝 Documentation | Document | Description | |----------|-------------| | [Architecture](doc/ARCHITECTURE.md) | Overall architecture + Multi-broker design | | [Nginx Config](doc/nginx/README.md) | Load balancing configuration | | [IM Core Features](doc/md/IM核心特性.md) | Four principles explained | | [ACK Queue](doc/md/ACK队列技术选型.md) | ACK mechanism | | [CHANGELOG](CHANGELOG.md) | Version history | --- ## 🛠️ Roadmap ### v1.2.0 (Current) ✅ - [x] Multi-broker support (RabbitMQ/Redis/RocketMQ) - [x] Load balancing (4 strategies) - [x] Flyway database migration - [x] Vue3 frontend rewrite - [x] Database optimization (27 indexes) - [x] BCrypt password encryption - [x] Global exception handling ### v1.3.0 (Planned) 🚧 - [ ] IM admin console - [ ] Data statistics dashboard - [ ] Real-time monitoring - [ ] Message moderation - [ ] Friend groups - [ ] Blacklist ### v2.0.0 (Future) 🔮 - [ ] Audio/video calls - [ ] Screen sharing - [ ] Mobile SDK - [ ] Elasticsearch message search - [ ] Kubernetes deployment --- ## 🏗️ Contributing ### Branches | Branch | Description | |--------|-------------| | master | Stable release | | develop | Development branch, accepts PR | ### How to Contribute 1. Fork the project 2. Create feature branch: `git checkout -b feature/xxx` 3. Commit changes: `git commit -m 'Add xxx'` 4. Push to branch: `git push origin feature/xxx` 5. Submit Pull Request ### Issues & Support - [Gitee Issue](https://gitee.com/brother-one/echo-im/issues) - WeChat group (see QR code below) --- ## 📞 Contact ![WeChat Group](doc/image/fbc33e8a11ed71b5ca6663fec6b80a9.jpg) --- ## 📜 License [MIT License](LICENSE) ---

⭐ Star if this project helps you! ⭐

Made with ❤️ by Echo IM Team
© 2024 Echo IM. All rights reserved.