Communication message processing method and device, gateway and storage medium
By using the kafka topic and message serial number mechanism in the message gateway, the reliability problem of communication messages during network interruption is solved, ensuring the successful transmission of messages and avoiding repeated sending and missed sending.
Patent Information
- Application Number
- CN202311616903.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-29
- Publication Date
- 2025-05-30
AI Technical Summary
In the prior art, the communication message is lost due to network interruption during transmission, or the sending side repeatedly sends it, and the reliability of the message cannot be guaranteed.
Save the communication messages into the kafka topic through the message gateway, and use the message sequence number mechanism to align them on the sending and receiving ends to ensure the successful transmission of messages and avoid repeated sending or missed transmission.
It improves the reliability of communication messages, avoids the problem of repeated sending on the sending side and missing messages on the receiving side, and realizes the reliability and reliability of message transmission.
Smart Images

Figure CN120075180A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technologies, and in particular, to a method, apparatus, gateway, and storage medium for processing communication messages. Background Art
[0002] In today's highly digital age, instant messaging plays an important role, making it a priority issue for developers of instant messaging software to ensure the reliability of messages.
[0003] Currently, in the prior art, a communication message is mainly sent by a sending end, transferred to a receiving end through a server; during the transfer process, the sending end sends a message sending request to the server, the server sends an approval for the message sending request to the sending end, and sends a message pushing request to the receiving end; the receiving end sends an approval for the message pushing request to the server; at this time, the server pushes the message to the receiving end and notifies the sending end that the message has been sent successfully.
[0004] However, if there is a network interruption between the server and the receiving end, the message cannot be pushed to the receiving end, but the sending end receives a notification of successful sending, which may cause the sending end to miss sending a message and the receiving end to lose the message; if there is a network interruption between the server and the sending end, the server pushes the message to the receiving end, but the sending end does not receive a notification of successful sending, which may cause the sending end to resend the message and the receiving end to receive the message repeatedly. Therefore, the reliability of communication messages cannot be guaranteed. Summary of the Invention
[0005] This application provides a method, apparatus, gateway, and storage medium for processing communication messages to solve the technical problem of inability to guarantee the reliability of communication messages.
[0006] In a first aspect, this application provides a method for processing communication messages, which is applied to a message gateway and includes:
[0007] Receiving a communication message sent by a sending user terminal through a pre-established session connection, where after sending the communication message, the sending user terminal writes the communication message into a local database and increments the corresponding sending user side message sequence number in the local database by one.
[0008] Obtaining a first message gateway instance corresponding to the sending user terminal in redis.
[0009] Invoking a message processing service through the first message gateway instance, saving the communication message to a corresponding topic in kafka, incrementing the corresponding first gateway side message sequence number in the redis by one, and sending a confirmation message of successful sending to the sending user terminal, so that the sending user terminal displays that the communication message has been sent successfully on the display interface.
[0010] If it is detected that the connection of the sending client is interrupted and the confirmation message of successful sending cannot be sent to the sending client, and when a re-established session connection of the sending client is detected, the current first gateway-side message sequence number is sent to the sending client, so that the sending client compares the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, the current sending client-side message sequence number is decremented by one, and it is displayed on the display interface that the communication message sending fails and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, it is displayed on the display interface that the communication message is sent successfully.
[0011] Detect whether the receiving client is online. If it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in the redis, and call the message push service through the second message gateway instance to send the communication message in the corresponding topic in the kafka to the receiving client.
[0012] Optionally, in the method as described above, the obtaining the second message gateway instance corresponding to the receiving client in the redis, calling the message push service through the second message gateway instance, and sending the communication message in the corresponding topic in the kafka to the receiving client includes: obtaining the second message gateway instance corresponding to the receiving client in the redis, calling the message push service through the second message gateway instance, and obtaining the communication message from the corresponding topic in the kafka; incrementing the corresponding second gateway-side message sequence number in the redis by one, and establishing a mapping relationship between the communication message and the current second gateway-side message sequence number; sending the mapping relationship to the receiving client, so that the receiving client parses the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number plus one, write the communication message into the local database, and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number plus one, obtain the missing communication message, write the missing communication message into the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, do nothing.
[0013] Optionally, in the method described above, after detecting whether the receiving client is online, the method further includes: if it is determined that the receiving client is offline, saving the communication message in the corresponding topic in Kafka to an offline message database; when detecting a re-established session connection of the receiving client, sending the current second gateway-side message sequence number to the receiving client, so that the receiving client compares the current second gateway-side message sequence number with the current receiving client-side message sequence number; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number, obtaining the communication message in the offline message database, saving the communication message to a local database, and incrementing the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number, not performing any operation; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, deleting the communication message in the local database, and assigning the current second gateway-side message sequence number to the current receiving client-side message sequence number.
[0014] Optionally, in the method described above, before receiving a communication message sent by a sending client, the method further includes: receiving a session connection request sent by the sending client through a first message gateway instance; verifying the session connection request to obtain a verification result, and sending the verification result to the sending client, so that the sending client determines whether the verification result is verification passed. If it is verification passed, establishing a session connection with the first message gateway instance of the message gateway; saving the mapping relationship between the session connection and the sending client; saving the mapping relationship between the first message gateway instance and the sending client to Redis.
[0015] Optionally, in the method described above, before receiving a communication message sent by a sending client, the method further includes: receiving a session connection request sent by the receiving client through a second message gateway instance; verifying the session connection request to obtain a verification result, and sending the verification result to the receiving client, so that the receiving client determines whether the verification result is verification passed. If it is verification passed, establishing a session connection with the second message gateway instance of the message gateway; saving the mapping relationship between the session connection and the receiving client; saving the mapping relationship between the second message gateway instance and the receiving client to Redis.
[0016] In a second aspect, the present application provides a method for processing communication messages, which is applied to a sending client and includes:
[0017] Send the communication message to the message gateway through a pre-established session connection, so that the message gateway obtains the first message gateway instance corresponding to the sending client in Redis, calls the message processing service through the first message gateway instance, saves the communication message to the corresponding topic in Kafka, and increments the corresponding first gateway-side message sequence number in Redis by one.
[0018] Write the communication message to the local database and increment the corresponding sending client-side message sequence number in the local database by one.
[0019] Receive the confirmation information of successful sending sent by the message gateway and display that the communication message is successfully sent on the display interface.
[0020] If the connection is interrupted, re-establish the session connection and receive the current first gateway-side message sequence number sent by the message gateway.
[0021] Compare the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, decrement the current sending client-side message sequence number by one and display on the display interface that the communication message fails to be sent and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, display on the display interface that the communication message is successfully sent.
[0022] In a third aspect, the present application provides a method for processing communication messages, which is applied to a receiving client and includes:
[0023] Receive a communication message sent by a message gateway, where the communication message is obtained by the message gateway detecting whether the receiving client is online. If it is determined that the receiving client is online, the second message gateway instance corresponding to the receiving client in Redis is obtained, and the message push service is called through the second message gateway instance to obtain from the corresponding topic in Kafka.
[0024] Optionally, for the method described above, receive the mapping relationship sent by the message gateway, where the mapping relationship is that the message gateway detects whether the receiving client is online. If it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in the redis, call the message push service through the second message gateway instance, and obtain the communication message from the corresponding topic in the kafka; increment the second gateway-side message sequence number corresponding to the receiving client in the redis by one, and establish the mapping relationship between the communication message and the current second gateway-side message sequence number; parse the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving user-side message sequence number plus one, write the communication message into the local database and increment the current receiving user-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving user-side message sequence number plus one, obtain the missing communication message, write the missing communication message into the local database, and assign the current second gateway-side message sequence number to the current receiving user-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving user-side message sequence number, do nothing.
[0025] Optionally, for the method described above, if the connection is interrupted, re-establish the session connection and receive the current second gateway-side message sequence number sent by the message gateway; before the message gateway sends the current second gateway-side message sequence number, save the communication message to the offline message database; compare the current second gateway-side message sequence number with the current receiving user-side message sequence number; if the current second gateway-side message sequence number is greater than the current receiving user-side message sequence number, obtain the communication message in the offline message database, save the communication message to the local database, and increment the current receiving user-side message sequence number by one; if the current second gateway-side message sequence number is equal to the current receiving user-side message sequence number, do nothing; if the current second gateway-side message sequence number is less than the current receiving user-side message sequence number, delete the communication message in the local database and assign the current second gateway-side message sequence number to the current receiving user-side message sequence number.
[0026] Fourthly, the present application provides a communication message processing device, which is applied to a message gateway and includes:
[0027] A receiving module, configured to receive communication messages sent by a sending client through a pre-established session connection. After sending the communication messages, the sending client writes the communication messages into a local database and increments the corresponding sending user-side message sequence number in the local database by one.
[0028] An obtaining module, configured to obtain a first message gateway instance corresponding to the sending client in Redis.
[0029] A first calling module, configured to call a message processing service through the first message gateway instance, save the communication messages to a corresponding topic in Kafka, increment the corresponding first gateway-side message sequence number in Redis by one, and send a confirmation message of successful sending to the sending client, so that the sending client displays that the communication message is successfully sent on a display interface.
[0030] A sending module, configured to, if it is detected that the connection of the sending client is interrupted and the confirmation message of successful sending cannot be sent to the sending client, and when a re-established session connection of the sending client is detected, send the current first gateway-side message sequence number to the sending client, so that the sending client compares the current first gateway-side message sequence number with the current sending user-side message sequence number; if the current first gateway-side message sequence number is less than the current sending user-side message sequence number, subtract one from the current sending user-side message sequence number and display on the display interface that the communication message sending fails and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending user-side message sequence number, display on the display interface that the communication message is successfully sent.
[0031] A second calling module, configured to detect whether a receiving client is online. If it is determined that the receiving client is online, obtain a second message gateway instance corresponding to the receiving client in Redis, and call a message push service through the second message gateway instance to send the communication messages in the corresponding topic in Kafka to the receiving client.
[0032] In a fifth aspect, the present application provides a communication message processing device, which is applied to a sending client and includes:
[0033] A sending module, configured to send communication messages to a message gateway through a pre-established session connection, so that the message gateway obtains a first message gateway instance corresponding to the sending client in Redis, calls a message processing service through the first message gateway instance, saves the communication messages to a corresponding topic in Kafka, and increments the corresponding first gateway-side message sequence number in Redis by one.
[0034] A saving module, configured to write the communication message into a local database and increment by one the sequence number of the message on the sending user side corresponding in the local database.
[0035] A first receiving module, configured to receive the confirmation information of successful sending sent by the message gateway and display that the communication message is successfully sent on a display interface.
[0036] A second receiving module, configured to re - establish a session connection if the connection is interrupted and receive the current first gateway - side message sequence number sent by the message gateway.
[0037] A comparison module, configured to compare the current first gateway - side message sequence number with the current sending user - side message sequence number; if the current first gateway - side message sequence number is less than the current sending user - side message sequence number, then decrement the current sending user - side message sequence number by one and display on the display interface that the communication message fails to be sent and needs to be resent; if the current first gateway - side message sequence number is equal to the current sending user - side message sequence number, then display on the display interface that the communication message is successfully sent.
[0038] In a sixth aspect, the present application provides a processing device for communication messages, applied to a receiving user - end, including:
[0039] A receiving module, configured to receive a communication message sent by a message gateway, where the communication message is that the message gateway detects whether the receiving user - end is online. If it is determined that the receiving user - end is online, then obtain a second message gateway instance corresponding to the receiving user - end in redis, and call a message push service through the second message gateway instance to obtain from a corresponding topic in kafka.
[0040] In a seventh aspect, the present application provides a message gateway, including: at least one processor and a memory;
[0041] The memory stores computer - executable instructions;
[0042] The at least one processor executes the computer - executable instructions stored in the memory, so that the at least one processor executes the processing method of the communication message as described in the first aspect above and various possible designs of the first aspect.
[0043] In an eighth aspect, the present application provides a sending user - end, including: at least one processor and a memory;
[0044] The memory stores computer - executable instructions;
[0045] The at least one processor executes the computer - executable instructions stored in the memory, so that the at least one processor executes the processing method of the communication message as described in the second aspect above and various possible designs of the second aspect.
[0046] In a ninth aspect, the present application provides a receiving client, including: at least one processor and a memory;
[0047] The memory stores computer-executable instructions;
[0048] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the processing method of the communication message described in the above third aspect and various possible designs of the third aspect.
[0049] In a tenth aspect, the present application provides a computer storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the processing method of the communication message described in the above first aspect and various possible designs of the first aspect is implemented.
[0050] In an eleventh aspect, the present application provides a computer storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the processing method of the communication message described in the above second aspect and various possible designs of the second aspect is implemented.
[0051] In a twelfth aspect, the present application provides a computer storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the processing method of the communication message described in the above third aspect and various possible designs of the third aspect is implemented.
[0052] For the communication message processing method, device, gateway and storage medium provided by the present application, during the communication message sending process, if the communication message is successfully saved to the corresponding topic of kafka via the message network, the communication message sending success is displayed on the display interface of the sending client, avoiding the problem of repeated sending of communication messages by the sending client; if it is detected that the connection of the sending client is interrupted and the confirmation information of successful sending cannot be sent to the sending client, and when the re-established session connection of the sending client is detected, the sending client compares the current first gateway-side message sequence number with the current sending user-side message sequence number, avoiding the problems of repeated sending and missed sending of communication messages by the sending client, thereby improving the reliability of communication messages. During the communication message pushing process, by consuming the communication messages in the topic in kafka, the message pushing service is called statelessly to send the communication messages to the receiving client, realizing the decoupling of the two events of sending and pushing the communication messages. In addition, by saving the mapping relationship between the second message gateway instance and the receiving client to redis, when pushing messages, only a push request is sent to the specified second message gateway, avoiding unnecessary resource waste. Description of the Drawings
[0053] The accompanying drawings herein are incorporated into and constitute a part of this specification, showing embodiments consistent with this application, and are used together with the specification to explain the principles of this application.
[0054] Figure 1 A schematic diagram of an application scenario of the communication message processing method provided for an embodiment of this application;
[0055] Figure 2 A schematic flowchart of the communication message processing method provided for an embodiment of this application;
[0056] Figure 3 A schematic structural diagram of the communication message processing apparatus provided for an embodiment of this application;
[0057] Figure 4 A schematic structural diagram of the communication message processing apparatus provided for another embodiment of this application;
[0058] Figure 5 A schematic structural diagram of the communication message processing apparatus provided for another embodiment of this application;
[0059] Figure 6 A schematic hardware structure diagram of the message gateway provided for an embodiment of this application;
[0060] Figure 7 A schematic hardware structure diagram of the sending client provided for another embodiment of this application;
[0061] Figure 8 A schematic hardware structure diagram of the receiving client provided for another embodiment of this application.
[0062] Through the above accompanying drawings, specific embodiments of this application have been shown, and there will be more detailed descriptions hereinafter. These drawings and textual descriptions are not intended to limit the scope of the concept of this application in any way, but to illustrate the concept of this application to those skilled in the art by referring to specific embodiments. Detailed Description of the Embodiments
[0063] Exemplary embodiments will be described in detail herein, and examples thereof are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. On the contrary, they are merely examples of devices and methods consistent with some aspects of this application as detailed in the appended claims.
[0064] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data that have been authorized by the user or fully authorized by all parties. Moreover, the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards, and corresponding operation entrances are provided for users to choose to authorize or refuse.
[0065] In today's highly digital age, instant messaging plays an important role, making it a priority issue for instant messaging software developers to ensure the reliability and real-time nature of messages. Currently, in the prior art, communication messages are mainly sent by the sending end, transferred through the server to the receiving end; during the transfer process, the sending end sends a message sending request to the server, the server sends an approval of the message sending request to the sending end, and sends a message push request to the receiving end; the receiving end sends an approval of the message push request to the server; at this time, the server pushes the message to the receiving end and notifies the sending end that the message has been sent successfully. However, if there is a network interruption between the server and the receiving end, the message cannot be pushed to the receiving end, but the sending end receives the notification of successful sending, which will cause the sending end to miss sending messages and the receiving end to lose messages; if there is a network interruption between the server and the sending end, the server pushes the message to the receiving end, but the sending end does not receive the notification of successful sending, which will cause the sending end to resend messages and the receiving end to receive messages repeatedly. Therefore, the reliability of communication messages cannot be guaranteed.
[0066] To solve the above technical problems, the embodiments of this application propose the following technical ideas: Considering that the sending end may resend messages and miss sending messages, and the receiving end may lose messages and receive messages repeatedly, resulting in the inability to guarantee the reliability of communication messages. The inventor thought of decoupling the two events of sending and receiving communication messages, and having the sending user terminal judge whether the communication message has been sent successfully according to the message alignment mechanism. If it is determined that the sending is successful, it will display on the display interface that the communication message has been sent successfully, avoiding the repeated sending of communication messages; if it is determined that the sending is not successful, it will display on the display interface that the communication sending has failed and needs to be resent, avoiding the missed sending of communication messages. The receiving user terminal judges whether the communication message has been received successfully according to the message alignment mechanism. If the reception fails, it will obtain the communication message in the offline database to avoid losing the communication message; if the reception is successful, it will not perform any operation to avoid receiving the communication message repeatedly, thereby improving the reliability of the communication message.
[0067] The method for processing communication messages provided by this application aims to solve the above technical problems of the prior art.
[0068] The following uses specific embodiments to elaborate in detail on the technical solution of this application and how the technical solution of this application solves the above technical problems. The following several specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0069] Figure 1 It is a schematic diagram of the application scenario of the communication message processing method provided by the embodiment of this application. As Figure 1 shown, this application scenario includes: a sending user terminal 101, a message gateway 102, and a receiving user terminal 103.
[0070] Referring to Figure 1 , the sending user terminal 101 establishes a session connection with the message gateway 102 to transfer communication messages and communication message-related data; the receiving user terminal 103 establishes a session connection with the message gateway 102 to transfer communication messages and communication message-related data;
[0071] Among them, the sending user terminal 101 sends a communication message to the message gateway 102; if the message gateway 102 determines that the receiving user terminal is in an online state, it sends the communication message to the receiving user terminal 103; the receiving user terminal 103 saves the communication message to the local database of the receiving user terminal.
[0072] Figure 2 It is a schematic flowchart of the communication message processing method provided by an embodiment of this application. The execution subject of this embodiment can be Figure 1 the message gateway 102 in the embodiment, or other message gateways with similar functions, and no special limitation is made here in this embodiment. As Figure 2 shown, this method includes:
[0073] S201: Receive a communication message sent by the sending user terminal through a pre-established session connection. After the sending user terminal sends the communication message, it writes the communication message into the local database and increments the sending user-side message sequence number corresponding to the local database by one.
[0074] Specifically, the process of pre-establishing the session connection is as follows: Receive the session connection request sent by the sending user terminal through the first message gateway instance; verify the session connection request to obtain a verification result, and send the verification result to the sending user terminal so that the sending user terminal can determine whether the verification result is verification passed. If it is verification passed, the establishment of the session connection with the first message gateway instance of the message gateway is completed; save the mapping relationship between the session connection and the sending user terminal; save the mapping relationship between the first message gateway instance and the sending user terminal to redis.
[0075] Optionally, save the mapping relationship between the session connection and the identifier of the sending client to the local cache of the message gateway.
[0076] In this embodiment, the message gateway is responsible for managing the connection session heartbeat and continuously reporting it. It sends a control frame Ping to the sending client every 10 seconds. The following three situations may occur during the heartbeat detection:
[0077] a. If the Pong frame data returned by the sending client is successfully received, update the timestamp of the session connection.
[0078] b. If the Pong frame data returned by the sending client is not received, execute a disconnection and reconnection logic.
[0079] c. If the Pong frame data returned by the sending client is not received continuously twice, execute an offline processing logic. In addition, the message gateway actively senses the heartbeat timestamps of all session connections and periodically and actively clears and closes the timeout sessions.
[0080] Optionally, the offline processing logic includes: modifying the login status of the sending user side to offline; clearing the information corresponding to the session connection.
[0081] S202: Obtain the first message gateway instance corresponding to the sending client in redis.
[0082] S203: Invoke the message processing service through the first message gateway instance, save the communication message to the corresponding topic in kafka, increment the first gateway-side message sequence number in redis by one, and send the confirmation information of successful sending to the sending client, so that the sending client displays that the communication message is successfully sent on the display interface.
[0083] In this embodiment, the first message gateway instance invokes the message processing service through the RPC protocol, and the message processing service writes the communication message into the topic of kafka as a producer.
[0084] S204: If it is detected that the connection of the sending client is interrupted and the confirmation information of successful sending cannot be sent to the sending client, and when the re-established session connection of the sending client is detected, send the current first gateway-side message sequence number to the sending client, so that the sending client compares the current first gateway-side message sequence number with the current sending user-side message sequence number; if the current first gateway-side message sequence number is less than the current sending user-side message sequence number, subtract one from the current sending user-side message sequence number and display that the communication message fails to be sent and needs to be resent on the display interface; if the current first gateway-side message sequence number is equal to the current sending user-side message sequence number, display that the communication message is successfully sent on the display interface.
[0085] S205: Detect whether the receiving client is online. If it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in Redis, and call the message push service through the second message gateway instance to send the communication messages in the corresponding topic in Kafka to the receiving client.
[0086] Specifically, receive the session connection request sent by the receiving client through the second message gateway instance; verify the session connection request to obtain a verification result, and send the verification result to the receiving client so that the receiving client can determine whether the verification result is verification passed. If it is verification passed, establish the session connection with the second message gateway instance of the message gateway; save the mapping relationship between the session connection and the receiving client; save the mapping relationship between the second message gateway instance and the receiving client to Redis.
[0087] Optionally, save the mapping relationship between the session connection and the identifier of the receiving client to the local cache of the message gateway.
[0088] Specifically, obtain the second message gateway instance corresponding to the receiving client in Redis, call the message push service through the second message gateway instance, and obtain the communication messages from the corresponding topic in Kafka; increment the second gateway-side message sequence number corresponding in Redis by one, and establish the mapping relationship between the communication messages and the current second gateway-side message sequence number; send the mapping relationship to the receiving client so that the receiving client can parse the mapping relationship to obtain the communication messages and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number plus one, write the communication messages to the local database and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number plus one, obtain the missing communication messages, write the missing communication messages to the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, do nothing.
[0089] In this embodiment, the second message gateway instance calls the message push service through the RPC protocol. The message push service, as a consumer, obtains the communication messages in the topic of Kafka, creates a primary key for the communication messages, and establishes the mapping relationship between the communication messages and the current second gateway-side message sequence number.
[0090] In this embodiment, if it is determined that the receiving client is offline, the communication messages in the corresponding topic in Kafka are saved to the offline message database; when the re-established session connection of the receiving client is detected, the current second gateway-side message sequence number is sent to the receiving client so that the receiving client compares the current second gateway-side message sequence number with the current receiving client-side message sequence number; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number, the communication messages in the offline message database are obtained, the communication messages are saved to the local database, and the current receiving client-side message sequence number is incremented by one; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number, no operation is performed; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, the communication messages in the local database are deleted, and the current second gateway-side message sequence number is assigned to the current receiving client-side message sequence number.
[0091] Optionally, the offline message database can be MongoDB.
[0092] As can be seen from the description of the above embodiments, during the process of sending communication messages, if the communication messages are successfully saved to the corresponding topic in Kafka via the message network, the successful sending of the communication messages is displayed on the display interface of the sending client, avoiding the problem of the sending client repeatedly sending communication messages; if it is detected that the connection of the sending client is interrupted and the confirmation information of the successful sending cannot be sent to the sending client, and when the re-established session connection of the sending client is detected, the sending client compares the current first gateway-side message sequence number with the current sending client-side message sequence number, avoiding the problems of the sending client repeatedly sending communication messages and missing the sending of communication messages, thereby improving the reliability of communication messages. In addition, during the process of pushing communication messages, by consuming the communication messages in the topic in Kafka, the message push service is called statelessly to send the communication messages to the receiving client, realizing the decoupling of the two events of sending and pushing communication messages; by saving the mapping relationship between the second message gateway instance and the receiving client to Redis, when pushing messages, only a push request is sent to the specified second message gateway, avoiding unnecessary resource waste.
[0093] In another embodiment of the present application, on the basis of the above embodiment, the process of sending communication messages is introduced in detail. The execution subject of this embodiment can be Figure 1 the sending client 101 in the shown embodiment, or other sending client devices with similar functions. There is no special limitation here in this embodiment, and specifically includes:
[0094] S206: Send the communication message to the message gateway through a pre-established session connection, so that the message gateway obtains the first message gateway instance corresponding to the sending client in Redis, calls the message processing service through the first message gateway instance, saves the communication message to the corresponding topic in Kafka, and increments the first gateway-side message sequence number corresponding in Redis by one.
[0095] Optionally, the pre-established session connection is established according to the WebSocket protocol. Among them, before establishing the session connection, the sending client responds to the login request of the sending user and saves the login information when the sending user logs in to the receiving client.
[0096] S207: Write the communication message to the local database and increment the sending client-side message sequence number corresponding in the local database by one.
[0097] Among them, the sending client-side message sequence number is monotonically continuous and increasing.
[0098] Optionally, the local database can be SQLite.
[0099] S208: Receive the confirmation information of successful sending sent by the message gateway and display that the communication message is successfully sent on the display interface.
[0100] S209: If the connection is interrupted, re-establish the session connection and receive the current first gateway-side message sequence number sent by the message gateway.
[0101] S210: Compare the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, subtract one from the current sending client-side message sequence number and display on the display interface that the communication message fails to be sent and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, display on the display interface that the communication message is successfully sent.
[0102] Specifically, according to the message alignment mechanism, comparing the current first gateway-side message sequence number with the current sending client-side message sequence number may result in the following two situations:
[0103] a. The current first gateway-side message sequence number is less than the current sending client-side message sequence number.
[0104] The message gateway fails to successfully save the communication message to the corresponding topic in Kafka, and the first gateway-side message sequence number is not truly incremented by one, indicating that the communication message is not successfully sent. Therefore, it is necessary to subtract one from the current sending client-side message sequence number and display on the display interface that the communication message fails to be sent and needs to be resent to prompt the sending-side user to resend the communication message.
[0105] b. The current first gateway-side message sequence number is equal to the current sending user-side message sequence number.
[0106] The message gateway successfully saves the communication message to the corresponding topic in Kafka, indicating that the communication message is successfully sent. Therefore, it is displayed on the display interface that the communication message is successfully sent to prompt the sending-side user that the communication message is successfully sent.
[0107] As can be seen from the description of the above embodiments, the sending user end compares the current first gateway-side message sequence number with the current sending user-side message sequence number to determine whether the communication message is successfully written by the message gateway into the corresponding topic in Kafka. If it is successfully written, it indicates that the communication message is successfully sent, and it is displayed on the display interface that the communication message is successfully sent to prompt the sending user end that the communication message is successfully sent, avoiding duplicate sending of communication messages; if it is not successfully written, it indicates that the communication message is not successfully sent, and it is displayed on the display interface that the communication message fails to be sent and needs to be resent to prompt the sending user end to resend the communication message, avoiding missed sending of communication messages, thereby improving the reliability of communication messages.
[0108] In another embodiment of the present application, on the basis of the above embodiment, the push process of the communication message is introduced in detail. The execution subject of this embodiment can be Figure 1 the receiving user end 103 in the illustrated embodiment, or other receiving user ends with similar functions. There is no special limitation here in this embodiment, and specifically includes:
[0109] S211: Receive the communication message sent by the message gateway, where the communication message is that the message gateway detects whether the receiving user end is online. If it is determined that the receiving user end is online, obtain the second message gateway instance corresponding to the receiving user end in Redis, and obtain it from the corresponding topic in Kafka by calling the message push service through the second message gateway instance.
[0110] Specifically, receive the communication message sent by the message gateway through the pre-established session connection. Among them, before establishing the session connection, the receiving user end responds to the login request of the receiving user and saves the login information when the receiving user logs in to the receiving user end.
[0111] In this embodiment, before receiving the communication message sent by the message gateway, send the login status of the receiving user end to the message gateway so that the message gateway detects whether the receiving user end is online.
[0112] Specifically, receive the mapping relationship sent by the message gateway. The mapping relationship is that the message gateway detects whether the receiving client is online. If it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in Redis, call the message push service through the second message gateway instance, and obtain the communication message from the corresponding topic in Kafka; increment the second gateway-side message sequence number corresponding in Redis by one, and establish the mapping relationship between the communication message and the current second gateway-side message sequence number; parse the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number plus one, write the communication message into the local database, and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number plus one, obtain the missing communication message, write the missing communication message into the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, do nothing.
[0113] Specifically, according to the message alignment mechanism, compare the current second gateway-side message sequence number with the current receiving client-side message sequence number, and the following three situations may occur:
[0114] a. The current second gateway-side message sequence number is equal to the current receiving client-side message sequence number plus one.
[0115] It indicates that there is no missing communication message. Write the communication message into the local database, and increment the current receiving client-side message sequence number by one; optionally, the local database can be SQLite.
[0116] b. The current second gateway-side message sequence number is greater than the current receiving client-side message sequence number plus one
[0117] It indicates that there are several missing communication messages between the message gateway and the receiving client. Obtain the missing communication messages, write the missing communication messages into the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number.
[0118] c. The current second gateway-side message sequence number is less than the current receiving client-side message sequence number.
[0119] It indicates that the communication message is pushed repeatedly, and do nothing.
[0120] In this embodiment, there may be a situation where the receiving client has been disconnected. Due to the heartbeat monitoring mechanism, the offline status of the receiving client has not been updated yet, and the information of the session connection has not been cleared either. However, the message gateway has sent the communication message to the receiving client but failed to send it successfully. When the receiving client logs in again or reconnects after disconnection, it will compare the current second gateway-side message sequence number and the current receiving client-side message sequence number according to the message alignment mechanism to correctly process the communication message.
[0121] Specifically, if the connection is interrupted, re-establish the session connection and receive the current second gateway-side message sequence number sent by the message gateway. Before the message gateway sends the current second gateway-side message sequence number, save the communication message to the offline message database. Compare the current second gateway-side message sequence number with the current receiving client-side message sequence number. If the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number, obtain the communication message from the offline message database, save the communication message to the local database, and increment the current receiving client-side message sequence number by one. If the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number, do nothing. If the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, delete the communication message in the local database and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number.
[0122] Specifically, if the receiving client logs in again or reconnects after disconnection, resulting in the connection being interrupted, re-establish the session connection. According to the message alignment mechanism, compare the current second gateway-side message sequence number with the current receiving client-side message sequence number. The following three situations may occur:
[0123] a. The current second gateway-side message sequence number is greater than the current receiving client-side message sequence number.
[0124] This indicates that there are offline messages. Obtain the communication message from the offline message database and increment the current receiving client-side message sequence number by one.
[0125] b. The current second gateway-side message sequence number is equal to the current receiving client-side message sequence number.
[0126] This indicates that the communication message in the local database is the latest, and do nothing.
[0127] c. The current second gateway-side message sequence number is less than the current receiving client-side message sequence number
[0128] It is described that there is a situation where the communication message sending fails due to a connection interruption. Delete the communication message in the local database and assign the current second gateway-side message sequence number to the current receiving user-side message sequence number.
[0129] As can be seen from the description of the above embodiments, if the receiving user end is online, receive the communication message, and compare the current second gateway-side message sequence number and the current receiving user-side message sequence number according to the message alignment mechanism. For the three possible situations, different measures are taken to ensure the correct processing of the communication message; if the receiving user end is not online, after the receiving user end re-establishes the session connection, compare the current second gateway-side message sequence number and the current receiving user-side message sequence number according to the message alignment mechanism. For the three possible situations, different measures are taken to ensure the correct processing of the communication message, thereby improving the reliability of the communication message.
[0130] Figure 3 It is a schematic structural diagram of a communication message processing device provided by an embodiment of the present application. As Figure 3 shown, the communication message processing device includes: a receiving module 301, an obtaining module 302, a first calling module 303, a sending module 304, and a second calling module 305.
[0131] The receiving module 301 is used to receive the communication message sent by the sending user end through a pre-established session connection. After the sending user end sends the communication message, it writes the communication message into the local database and increments the corresponding sending user-side message sequence number in the local database by one.
[0132] The obtaining module 302 is used to obtain the first message gateway instance corresponding to the sending user end in redis.
[0133] The first calling module 303 is used to call the message processing service through the first message gateway instance, save the communication message to the corresponding topic in kafka, increment the corresponding first gateway-side message sequence number in the redis by one, and send the confirmation information of successful sending to the sending user end, so that the sending user end displays that the communication message is sent successfully on the display interface.
[0134] A sending module 304, configured to: if it is detected that the connection of the sending client is interrupted and the confirmation message of successful sending cannot be sent to the sending client, and when a re-established session connection of the sending client is detected, send the current first gateway-side message sequence number to the sending client, so that the sending client compares the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, subtract one from the current sending client-side message sequence number, and display that the communication message sending fails and needs to be resent on the display interface; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, display that the communication message is sent successfully on the display interface.
[0135] A second calling module 305, configured to detect whether the receiving client is online. If it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in the redis, and call the message push service through the second message gateway instance to send the communication message in the corresponding topic in the kafka to the receiving client.
[0136] Optionally, for the method as described above, the second calling module 305 is specifically configured to: obtain the second message gateway instance corresponding to the receiving client in the redis, call the message push service through the second message gateway instance, and obtain the communication message from the corresponding topic in the kafka; increment the second gateway-side message sequence number corresponding to the redis by one, and establish a mapping relationship between the communication message and the current second gateway-side message sequence number; send the mapping relationship to the receiving client, so that the receiving client parses the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number plus one, write the communication message into the local database, and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number plus one, obtain the missing communication message, write the missing communication message into the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, do nothing.
[0137] Optionally, for the method described above, the device further includes: a saving module 306, configured to save the communication messages in the corresponding topic in Kafka to an offline message database if it is determined that the receiving client is offline; when detecting a re-established session connection of the receiving client, send the current second gateway-side message sequence number to the receiving client, so that the receiving client compares the current second gateway-side message sequence number with the current receiving client-side message sequence number; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number, obtain the communication messages in the offline message database, save the communication messages to the local database, and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number, do nothing; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, delete the communication messages in the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number.
[0138] Optionally, for the method described above, the device further includes: a establishing module 307, configured to receive a session connection request sent by a sending client through a first message gateway instance; verify the session connection request to obtain a verification result, and send the verification result to the sending client, so that the sending client determines whether the verification result is verification passed. If it is verification passed, complete the establishment of the session connection with the first message gateway instance of the message gateway; save the mapping relationship between the session connection and the sending client; save the mapping relationship between the first message gateway instance and the sending client to Redis.
[0139] Optionally, for the method described above, the establishing module 307 is further configured to receive a session connection request sent by a receiving client through a second message gateway instance; verify the session connection request to obtain a verification result, and send the verification result to the receiving client, so that the receiving client determines whether the verification result is verification passed. If it is verification passed, complete the establishment of the session connection with the second message gateway instance of the message gateway; save the mapping relationship between the session connection and the receiving client; save the mapping relationship between the second message gateway instance and the receiving client to Redis.
[0140] Figure 4 This is a schematic structural diagram of a communication message processing device provided by another embodiment of the present application. As Figure 4 shown, the communication message processing device includes: a sending module 401, a saving module 402, a first receiving module 403, a second receiving module 404, and a comparing module 405.
[0141] A sending module 401, configured to send a communication message to a message gateway through a pre-established session connection, so that the message gateway obtains a first message gateway instance corresponding to the sending client in redis, calls a message processing service through the first message gateway instance, saves the communication message to a corresponding topic in kafka, and increments the first gateway-side message sequence number corresponding in the redis by one.
[0142] A saving module 402, configured to write the communication message into a local database, and increment the sending client-side message sequence number corresponding in the local database by one.
[0143] A first receiving module 403, configured to receive a confirmation message of successful sending sent by the message gateway, and display that the communication message is successfully sent on a display interface.
[0144] A second receiving module 404, configured to re-establish a session connection if the connection is interrupted, and receive the current first gateway-side message sequence number sent by the message gateway.
[0145] A comparison module 405, configured to compare the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, then decrement the current sending client-side message sequence number by one, and display on the display interface that the communication message fails to be sent and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, then display on the display interface that the communication message is successfully sent.
[0146] Figure 5 This is a schematic structural diagram of a communication message processing device provided in another embodiment of the present application. As Figure 5 shown, the communication message processing device includes: a receiving module 501.
[0147] The receiving module 501 is configured to receive a communication message sent by a message gateway, where the communication message is obtained by the message gateway detecting whether the receiving client is online, and if it is determined that the receiving client is online, obtaining a second message gateway instance corresponding to the receiving client in redis, and calling a message push service through the second message gateway instance to obtain from a corresponding topic in kafka.
[0148] Optionally, for the method described above, the receiving module 501 is specifically configured to: receive the mapping relationship sent by the message gateway, where the mapping relationship is that the message gateway detects whether the receiving client is online. If it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in redis, call the message push service through the second message gateway instance, and obtain the communication message from the corresponding topic in kafka; increment the second gateway-side message sequence number corresponding to the receiving client in redis by one, and establish the mapping relationship between the communication message and the current second gateway-side message sequence number; parse the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number plus one, write the communication message into the local database, and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number plus one, obtain the missing communication message, write the missing communication message into the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, do nothing.
[0149] Optionally, for the method described above, the receiving module 501 is further configured to, if the connection is interrupted, re-establish the session connection and receive the current second gateway-side message sequence number sent by the message gateway; before the message gateway sends the current second gateway-side message sequence number, save the communication message to the offline message database; compare the current second gateway-side message sequence number with the current receiving client-side message sequence number; if the current second gateway-side message sequence number is greater than the current receiving client-side message sequence number, obtain the communication message in the offline message database, save the communication message to the local database, and increment the current receiving client-side message sequence number by one; if the current second gateway-side message sequence number is equal to the current receiving client-side message sequence number, do nothing; if the current second gateway-side message sequence number is less than the current receiving client-side message sequence number, delete the communication message in the local database, and assign the current second gateway-side message sequence number to the current receiving client-side message sequence number.
[0150] Figure 6 This is a schematic hardware structure diagram of the message gateway provided by an embodiment of the present application. As Figure 6 shown, the message gateway includes: a processor 601 and a memory 602.
[0151] The memory 602 is used to store computer execution instructions.
[0152] A processor 601 for executing computer-executable instructions stored in a memory to implement the various steps performed in the above embodiments. For details, reference may be made to the relevant descriptions in the foregoing method embodiments.
[0153] Optionally, the memory 602 can be either independent or integrated with the processor 601.
[0154] When the memory 602 is independently provided, the message gateway further includes a bus 603 for connecting the memory 602 and the processor 601.
[0155] Figure 7 The figure shows a schematic hardware structure diagram of a sending client provided in another embodiment of the present application. As Figure 7 shown, the message gateway includes: a processor 701 and a memory 702.
[0156] A memory 702 for storing computer-executable instructions.
[0157] A processor 701 for executing computer-executable instructions stored in the memory to implement the various steps performed in the above embodiments. For details, reference may be made to the relevant descriptions in the foregoing method embodiments.
[0158] Optionally, the memory 702 can be either independent or integrated with the processor 701.
[0159] When the memory 702 is independently provided, the sending client further includes a bus 703 for connecting the memory 702 and the processor 701.
[0160] Figure 8 The figure shows a schematic hardware structure diagram of a receiving client provided in another embodiment of the present application. As Figure 8 shown, the message gateway includes: a processor 801 and a memory 802.
[0161] A memory 802 for storing computer-executable instructions.
[0162] A processor 801 for executing computer-executable instructions stored in the memory to implement the various steps performed in the above embodiments. For details, reference may be made to the relevant descriptions in the foregoing method embodiments.
[0163] Optionally, the memory 802 can be either independent or integrated with the processor 801.
[0164] When the memory 802 is independently provided, the receiving client further includes a bus 803 for connecting the memory 802 and the processor 801.
[0165] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the communication message processing method as described above is implemented.
[0166] An embodiment of the present application also provides a computer program product, including a computer program, and when the computer program is executed by a processor, the communication message processing method as described above is implemented.
[0167] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.
[0168] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0169] It should be understood that the above-mentioned device embodiments are only illustrative, and the device of the present application can also be implemented in other ways. For example, the division of units / modules in the above-mentioned embodiments is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.
[0170] In addition, unless otherwise specified, each functional unit / module in each embodiment of the present application may be integrated into one unit / module, each unit / module may exist physically separately, or two or more units / modules may be integrated together. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of a software program module.
[0171] When the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc.
[0172] When the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in the various embodiments of the present application. The aforementioned memory includes: USB flash drives, read-only memory (ROM), random access memory (RAM), mobile hard disks, magnetic disks, or optical discs, etc., all of which can store program codes.
[0173] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as within the scope described in this specification.
[0174] Other embodiments of the present application will be readily apparent to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. The present application is intended to cover any variations, uses, or adaptations of the present application, which follow the general principles of the present application and include known common general knowledge or conventional technical means in the technical field not disclosed in the present application. The specification and examples are only illustrative, and the true scope and spirit of the present application are pointed out by the following claims.
[0175] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.
Claims
1. A method for processing communication messages, characterized in that, applied to a message gateway, including: Receiving a communication message sent by a sending client through a pre-established session connection, wherein after sending the communication message, the sending client writes the communication message into the local database and increments the corresponding sending user side message sequence number in the local database by one; Obtaining a first message gateway instance corresponding to the sending client in redis; Invoking a message processing service through the first message gateway instance, saving the communication message to a corresponding topic in kafka, incrementing the corresponding first gateway side message sequence number in the redis by one, and sending a confirmation message of successful sending to the sending client, so that the sending client displays that the communication message is successfully sent on the display interface; If it is detected that the connection of the sending client is interrupted and the confirmation message of successful sending cannot be sent to the sending client, and when a re-established session connection of the sending client is detected, then send the current first gateway side message sequence number to the sending client, so that the sending client compares the current first gateway side message sequence number with the current sending user side message sequence number; if the current first gateway side message sequence number is less than the current sending user side message sequence number, then decrement the current sending user side message sequence number by one and display on the display interface that the communication message sending fails and needs to be resent; if the current first gateway side message sequence number is equal to the current sending user side message sequence number, then display on the display interface that the communication message is successfully sent; Detecting whether the receiving client is online, if it is determined that the receiving client is online, then obtaining a second message gateway instance corresponding to the receiving client in the redis, and invoking a message push service through the second message gateway instance to send the communication message in the corresponding topic in the kafka to the receiving client.
2. The method according to claim 1, characterized in that, The obtaining the second message gateway instance corresponding to the receiving client in the redis, invoking a message push service through the second message gateway instance, and sending the communication message in the corresponding topic in the kafka to the receiving client includes: Obtaining the second message gateway instance corresponding to the receiving client in the redis, and invoking a message push service through the second message gateway instance to obtain the communication message from the corresponding topic in the kafka; Incrementing the corresponding second gateway side message sequence number in the redis by one, and establishing a mapping relationship between the communication message and the current second gateway side message sequence number; Send the mapping relationship to the receiving client, so that the receiving client parses the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; if the current second gateway-side message sequence number is equal to the current receiving user-side message sequence number plus one, write the communication message into the local database and increment the current receiving user-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current receiving user-side message sequence number plus one, obtain the missing communication message, write the missing communication message into the local database, and assign the current second gateway-side message sequence number to the current receiving user-side message sequence number; if the current second gateway-side message sequence number is less than the current receiving user-side message sequence number, do nothing.
3. The method according to claim 1, wherein, after detecting whether the receiving client is online, further comprising: if it is determined that the receiving client is offline, save the communication message in the corresponding topic in the kafka to the offline message database; when detecting the re-established session connection of the receiving client, send the current second gateway-side message sequence number to the receiving client, so that the receiving client compares the current second gateway-side message sequence number with the current receiving user-side message sequence number; if the current second gateway-side message sequence number is greater than the current receiving user-side message sequence number, obtain the communication message in the offline message database, save the communication message to the local database, and increment the current receiving user-side message sequence number by one; if the current second gateway-side message sequence number is equal to the current receiving user-side message sequence number, do nothing; if the current second gateway-side message sequence number is less than the current receiving user-side message sequence number, delete the communication message in the local database and assign the current second gateway-side message sequence number to the current receiving user-side message sequence number.
4. The method according to any one of claims 1-3, wherein, before receiving the communication message sent by the sending client, further comprising: receive the session connection request sent by the sending client through the first message gateway instance; verify the session connection request to obtain a verification result, and send the verification result to the sending client, so that the sending client determines whether the verification result is verification passed. If it is verification passed, complete the establishment of the session connection with the first message gateway instance of the message gateway; save the mapping relationship between the session connection and the sending client; save the mapping relationship between the first message gateway instance and the sending client to the redis.
5. The method according to any one of claims 1-3, wherein, before receiving the communication message sent by the sending client, further comprising: receive the session connection request sent by the receiving client through the second message gateway instance; Verify the session connection request to obtain a verification result, and send the verification result to the receiving client, so that the receiving client determines whether the verification result is a successful verification. If it is a successful verification, establish a session connection with the second message gateway instance of the message gateway; Save the mapping relationship between the session connection and the receiving client; Save the mapping relationship between the second message gateway instance and the receiving client to the redis.
6. A method for processing communication messages, characterized in that, applied to a sending client, including: Send a communication message to the message gateway through a pre-established session connection, so that the message gateway obtains the first message gateway instance corresponding to the sending client in the redis, calls the message processing service through the first message gateway instance, saves the communication message to the corresponding topic in the kafka, and increments the corresponding first gateway-side message sequence number in the redis by one; Write the communication message into the local database, and increment the corresponding sending client-side message sequence number in the local database by one; Receive the confirmation information of successful sending sent by the message gateway, and display that the communication message is successfully sent on the display interface; If the connection is interrupted, re-establish the session connection, and receive the current first gateway-side message sequence number sent by the message gateway; Compare the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, subtract one from the current sending client-side message sequence number, and display on the display interface that the communication message fails to be sent and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, display on the display interface that the communication message is successfully sent.
7. A method for processing communication messages, characterized in that, applied to a receiving client, including: Receive a communication message sent by the message gateway, where the communication message is that the message gateway detects whether the receiving client is online. If it determines that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in the redis, and call the message push service through the second message gateway instance to obtain from the corresponding topic in the kafka.
8. According to the method described in claim 7, characterized in that, Receiving the communication message sent by the message gateway includes: Receive the mapping relationship sent by the message gateway, where the mapping relationship is that the message gateway detects whether the receiving client is online. If it determines that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in the redis, call the message push service through the second message gateway instance, obtain the communication message from the corresponding topic in the kafka; increment the corresponding second gateway-side message sequence number in the redis by one, and establish the mapping relationship between the communication message and the current second gateway-side message sequence number. Analyze the mapping relationship to obtain the communication message and the current second gateway-side message sequence number; If the current second gateway-side message sequence number is equal to the current received user-side message sequence number plus one, write the communication message to the local database and increment the current received user-side message sequence number by one; if the current second gateway-side message sequence number is greater than the current received user-side message sequence number plus one, obtain the missing communication message, write the missing communication message to the local database, and assign the current second gateway-side message sequence number to the current received user-side message sequence number; if the current second gateway-side message sequence number is less than the current received user-side message sequence number, do nothing.
9. The method according to claim 7, wherein, after receiving the communication message sent by the receiving message gateway, further comprising: If the connection is interrupted, re-establish the session connection and receive the current second gateway-side message sequence number sent by the message gateway; before the message gateway sends the current second gateway-side message sequence number, save the communication message to the offline message database; Compare the current second gateway-side message sequence number with the current received user-side message sequence number; if the current second gateway-side message sequence number is greater than the current received user-side message sequence number, obtain the communication message in the offline message database, save the communication message to the local database, and increment the current received user-side message sequence number by one; if the current second gateway-side message sequence number is equal to the current received user-side message sequence number, do nothing; if the current second gateway-side message sequence number is less than the current received user-side message sequence number, delete the communication message in the local database and assign the current second gateway-side message sequence number to the current received user-side message sequence number.
10. A communication message processing device, wherein, applied to a message gateway, comprising: a receiving module, configured to receive a communication message sent by a sending user terminal through a pre-established session connection, wherein after the sending user terminal sends the communication message, write the communication message to the local database and increment the corresponding sending user-side message sequence number in the local database by one; an obtaining module, configured to obtain the first message gateway instance corresponding to the sending user terminal in redis; a first calling module, configured to call a message processing service through the first message gateway instance, save the communication message to a corresponding topic in kafka, increment the corresponding first gateway-side message sequence number in the redis by one, and send a confirmation message of successful sending to the sending user terminal, so that the sending user terminal displays that the communication message is successfully sent on the display interface; A sending module, configured to, if it is detected that the connection of the sending client is interrupted and the confirmation message of successful sending cannot be sent to the sending client, and when a re-established session connection of the sending client is detected, send the current first gateway-side message sequence number to the sending client, so that the sending client compares the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, subtract one from the current sending client-side message sequence number, and display on the display interface that the communication message sending fails and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, display on the display interface that the communication message is sent successfully. A second calling module, configured to detect whether the receiving client is online, and if it is determined that the receiving client is online, obtain the second message gateway instance corresponding to the receiving client in the redis, call the message push service through the second message gateway instance, and send the communication message in the corresponding topic in the kafka to the receiving client.
11. A communication message processing device Characterized in that Applied to a sending client, it includes: A sending module, configured to send a communication message to a message gateway through a pre-established session connection, so that the message gateway obtains the first message gateway instance corresponding to the sending client in the redis, calls the message processing service through the first message gateway instance, saves the communication message to the corresponding topic in the kafka, and increments the corresponding first gateway-side message sequence number in the redis by one. A saving module, configured to write the communication message into a local database, and increment the corresponding sending client-side message sequence number in the local database by one. A first receiving module, configured to receive the confirmation message of successful sending sent by the message gateway, and display on the display interface that the communication message is sent successfully. A second receiving module, configured to re-establish a session connection if the connection is interrupted, and receive the current first gateway-side message sequence number sent by the message gateway. A comparison module, configured to compare the current first gateway-side message sequence number with the current sending client-side message sequence number; if the current first gateway-side message sequence number is less than the current sending client-side message sequence number, subtract one from the current sending client-side message sequence number, and display on the display interface that the communication message sending fails and needs to be resent; if the current first gateway-side message sequence number is equal to the current sending client-side message sequence number, display on the display interface that the communication message is sent successfully.
12. A communication message processing device Characterized in that Applied to a receiving client, it includes: A receiving module, configured to receive communication messages sent by a message gateway, where the communication messages are that the message gateway detects whether the receiving client is online. If it is determined that the receiving client is online, a second message gateway instance corresponding to the receiving client in Redis is obtained, and the message push service is called through the second message gateway instance to obtain from the corresponding topic in Kafka.
13. A message gateway Characterized in that It includes: A processor and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the communication message processing method according to any one of claims 1-5.
14. A sending client Characterized in that It includes: A processor and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the communication message processing method according to claim 6.
15. A receiving client Characterized in that It includes: A processor and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the communication message processing method according to any one of claims 7-9.
16. A computer-readable storage medium Characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the communication message processing method according to any one of claims 1-5 is implemented.
17. A computer-readable storage medium Characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the communication message processing method according to claim 6 is implemented.
18. A computer-readable storage medium Characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the communication message processing method according to any one of claims 7-9 is implemented.
Citation Information
Patent Citations
Message transmission method and equipment
CN102571635A
Reliable message pushing method based on XMPP
CN104954348A
Multicast communication method, terminal equipment and storage medium
CN110022218A
Distributed transaction processing method and system based on message queue
CN111158933A
Message pushing method and device, electronic equipment and computer readable medium
CN115004673A