The message transmission process is divided into three stages:
Among them, the uplink and downlink of the message are guaranteed by C/S full duplex communication, and the heartbeat ensures the availability of the channel.
Message processing is realized by im-server, which mainly includes message authentication, message audit and message unpacking. It must be stable and efficient, and can be realized through independent services to ensure its scalability.
For group messages, unpacking is required, and 1 sent packet generates n received packets, where n is the number of current group members.
In a single chat session between user 1 and user 2, user 1 sent three messages, namely aa, bb and cc.
Among them, aa and cc were successfully sent, and bb failed to be sent after the client automatically retried for 3 minutes due to network or equipment problems. Whether to resend will display a small button, and the user can decide whether to resend.
If the user clicks the button to resend bb, how will the message list of user 1 and user2 be displayed?
In a single chat session between user 1 and user 2, user 1 sent three messages, namely aa, bb and cc.
Among them, aa was sent successfully, bb and cc are being retransmitted automatically, user2 sent dd and ee, and user2 sent successfully. After that, bb and cc were automatically forwarded successfully.
So, how will the message list of user 1 and user2 be displayed?
In the group chat sessions of user 1, user 2 and user 3, user 1 and user 2 send messages to im-server at the same time, even time stamps generated by im-server.
So, how to show the message list of user 1, user2 and user3?
The orderliness of messages is more of a user experience.
How to realize the reliability of the message and ensure that the message is neither heavy nor leaking needs to start from three links of message transmission.
In the process of c- > in S, send-ack is adopted. If the client does not receive the send-ack, it will automatically retransmit it.
This process can ensure that the news will not be leaked. However, the message received by the server may be duplicate. If there is a message with a duplicate sequenceId, the server must copy it.
The server may involve multiple services in the process of processing messages, such as SessionManager and Auditor.
In order to ensure the reliability of the message, every interaction with RabbitMQ needs to ensure successful delivery and safe consumption.
In the process of s- > in C, the method of receive-ack is adopted. If the server does not receive the receive-ack, it will automatically retransmit it.
This process can ensure that the news will not be leaked. However, the message received by the receiver may be duplicate. If there is a message with a duplicate sequenceId, the receiver must copy it.
If the receiver is not online, when the receiver is online, it can obtain historical messages through API, and check the historical message list twice (the server must complete the first check) to ensure that there are no messages with duplicate sequenceId.
IM system is not standard. Although XMPP protocol tries to solve this problem, it turns out to be unrealistic.
Almost all IM vendors have their own proprietary protocols and different implementation logics, which also determines that even for the same technical problem, it is difficult for IM to have a fixed implementation routine and standard solution.
However, several hard indicators of IM system must be realized.
In the process of implementation, we need to consider the cost performance, whether to pursue higher system concurrency or more reliable data flow; Whether to pursue greater system throughput or better scalability and disaster tolerance.
Finally, I recommend an IM column:
/u/jackjiang