introduce

Easy-im is a lightweight, out-of-the-box instant messaging system for developers, helping developers quickly build message push and other functions. With easy-IM, you can quickly implement the following features:

+ Chat software

+ IoT message push

Basic Usage – Standalone (V1 branch)

The project is divided into three modules: Easy-IM-client, Easy-IM-Server and Easy-IM-Common.

On the server side, run the MVN package command to generate easy-IM-server.tar. gz, decompress the package to the./lib directory, and run the following command: Java-jar-dport =8888 easy-im-server-1.0-snapshot. jar, where port is the service port, can start the server.

On the client, run the MVN package command to generate easy-IM-client.tar. gz, decompress the package to the./lib directory, and run the following command: Java-jar-duserid =110 -dusername = zhangsan-dhost =127.0.0.1 -dport =8888 easy-IM-client-1.0-snapshot.jar Userid is the userid, username is the username, host is the server IP address, and port is the server port. The userid must be unique.

Usage: After the client is started, enter the command in the command::content format. The command is delimited by double colons (:). The following commands are supported:

+ single chat sendToUser: : userId: : MSG

+ group chat sendToGroup: : groupId: : MSG

+ a group chat createGroup: : userId1, userId2 userId3...

+ radio broadcast: : MSG

More commands are planned to be added later, such as:

+ quitGroup::groupId

JoinGroup ::groupId

+ Query all online users getAllUsers

+ Query getGroupUsers::groupId of online users in group chats


Planned – Cluster Version (V2 branch)

The intention is to make the server an infinitely scalable architecture to meet the high concurrency requirements. It can be divided into the following steps:

Add routing layer: all sent messages are forwarded to the responding server by the routing layer, and then the server is forwarded to the client through the long connection, so as to solve the problem that the sender and receiver are not on the same server and cannot communicate

Add storage media: Store all group relationships, client and server relationships, user information, etc. You can use Redis or MySQL, or store historical messages

Add service governance: if the server wants to expand infinitely, it must use the mechanism of service registration and service discovery, which can be implemented by ZooKeeper or Eureka

The architecture diagram is as follows:

Interactive steps:

1. Start the server and register the server with the registry
2. Start the Route layer and go to the registry to obtain the list of available servers
3. Start client and obtain a server information from route (Route layer implements selection strategy, default round robin)
4. The client establishes a long-term connection with the server and stores the mapping between the server and the client to Redis or MySQL

Note:

1. Route layer uses HTTP to provide stateless services externally, and can use nginx unlimited extension
2. The server is registered to the registry and can be extended indefinitely to achieve millions of connections
3. When clients communicate with each other, they need to send a message to route, which searches for the corresponding server in Redis and forwards the message to the client of the other party through the server. In this way, the two clients can communicate with each other when they are on different servers

At present, cluster version (v2 branch) is being planned, welcome interested students to join us and make progress together.


Contact the author

  • Wechat official account