WS disconnection message processing method and device, computer equipment and medium
By using a server-side caching queue mechanism and distributed storage, the problem of message loss after WS connection is resolved, ensuring message integrity and order, and improving business reliability and user experience.
Patent Information
- Application Number
- CN202511465224.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-14
- Publication Date
- 2025-12-30
AI Technical Summary
After the WS connection is lost, existing technologies result in message loss and incomplete data, affecting normal business operations. Furthermore, the limited local cache capacity of the client makes it impossible to guarantee the reliable storage and recovery of messages, making it difficult to achieve message synchronization between multiple clients.
By establishing a caching queue mechanism on the server side, messages are cached when the WS connection fails and sent in order after the connection is restored. Combined with memory queues and distributed storage, the integrity and order of messages are ensured, supporting large-scale message storage and multi-client synchronization.
This effectively prevents message loss when the WS connection is lost, ensuring message integrity and order, and improving business reliability and user experience.
Smart Images

Figure CN121239729A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of Internet, and in particular to a WS disconnection message processing method and device, computer equipment and a medium. BACKGROUND
[0002] In a WebSocket (WS) communication scenario, when the WS connection is unexpectedly disconnected due to network fluctuations, device abnormalities and other reasons, the messages being transmitted may be lost. In order to ensure a certain message integrity and order, the server currently mainly discards the failed messages, or only a small amount of local cache is performed at the client.
[0003] However, this method may result in incomplete data, thereby affecting the normal operation of the business. In addition, due to the limited capacity of the client local cache, and the inability to guarantee the reliability of message storage and recovery when the client is restarted or the device is switched, it is also difficult to achieve message synchronization between multiple clients. It can be seen that neither the server discarding the failed messages nor the client local small cache method can guarantee the integrity and order of the data after the WS disconnection. SUMMARY
[0004] Embodiments of the present application provide a WS disconnection message processing method, device, computer equipment and medium, aiming to solve the problem that in the prior art, after the WS connection is disconnected, the data is incomplete due to discarding messages, thereby affecting the normal operation of the business, and due to the limited capacity of the client local cache, and the inability to guarantee the reliability of message storage and recovery when the client is restarted or the device is switched, it is also difficult to achieve message synchronization between multiple clients.
[0005] In a first aspect, the embodiments of the present application provide a WS disconnection message processing method, which comprises: A first WS client establishes a WS connection with the message processing engine; the method comprises: Receiving a first message; wherein the first message is generated by a message sending module in the message processing engine and sent to the first WS client, and is a message that fails to be sent after the WS connection is abnormal; According to the pre-stored WS connection information queried, the first message is forwarded to the first WS client; When detecting that the WS connection is abnormal, the first message and a second message are cached according to the message generation timestamp; the second message is generated by a message sending module in the message processing engine and sent to the first WS client, and is a message that is not sent after the first message; Querying a historical failed message that is not sent to the first WS client from a network cache unit; After detecting that the WS connection is normal, the first message and the second message are sent to the first WS client in sequence according to the message generation time stamp.
[0006] In a second aspect, the embodiments of the present application further provide a WS disconnection message processing device, which comprises: The transceiving unit is configured to receive the first message, wherein the first message is generated by the message sending module in the message processing engine and sent to the first WS client, and is a message that fails to be sent after WS connection is abnormal; The processing unit is configured to forward the first message to the first WS client through the transceiving unit according to the queried pre-stored WS connection information, and cache the first message and the second message according to the message generation time stamp after detecting that the WS connection is abnormal, wherein the second message is generated by the message sending module in the message processing engine and sent to the first WS client, and is a message that is not sent after the first message. The processing unit is further configured to query the first message and the second message that are not sent to the first WS client from the network cache unit after detecting that the WS connection is normal, and send the first message and the second message to the first WS client in sequence through the transceiving unit according to the message generation time stamp.
[0007] In a third aspect, the embodiments of the present application further provide a computer device, which comprises a memory and a processor, the memory stores a computer program, and the processor implements the method of the first aspect when executing the computer program.
[0008] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program, and the computer program comprises program instructions, and the program instructions can implement the method of the first aspect when executed by a processor.
[0009] The embodiments of the present application provide a WS disconnection message processing method, device, computer device and medium, the method comprising: receiving a first message; forwarding the first message to the first WS client according to the queried pre-stored WS connection information; caching the first message and a second message according to the message generation time stamp after detecting that the WS connection is abnormal, wherein the second message is a message that is not sent after the first message; querying historical failed messages that are not sent to the first WS client from a network cache unit; and sending the first message and the second message to the first WS client in sequence according to the message generation time stamp after detecting that the WS connection is normal. Through the message caching, storage and recovery mechanism, the embodiments of the present application effectively avoid the loss of messages when the WS connection is disconnected, guarantee the integrity of the messages, and improve the reliability of the business. BRIEF DESCRIPTION OF DRAWINGS
[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed in the embodiment description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without any creative effort based on these drawings.
[0011] Figure 1 The application scenario diagram of the WS disconnection message processing method provided by the embodiment of the present application is shown in the figure. Figure 2 The flowchart of the WS disconnection message processing method provided by the embodiment of the present application is shown in the figure. Figure 3 The sub-flowchart of the WS disconnection message processing method provided by the embodiment of the present application is shown in the figure. Figure 4 Another sub-flowchart of the WS disconnection message processing method provided by the embodiment of the present application is shown in the figure. Figure 5 Still another sub-flowchart of the WS disconnection message processing method provided by the embodiment of the present application is shown in the figure. Figure 6 The schematic block diagram of the WS disconnection message processing device provided by the embodiment of the present application is shown in the figure. Figure 7 The schematic block diagram of the computer device provided by the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0012] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without any creative effort belong to the scope of protection of the present application.
[0013] It should be understood that, when used in the specification and the appended claims, the terms "comprise" and "include" indicate the presence of described features, integers, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0014] It should also be understood that the terms used in the present application specification are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the present application specification and the appended claims, unless otherwise clearly indicated by the context, the singular forms "a", "an" and "the" are intended to include the plural forms.
[0015] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0016] This invention provides a method, apparatus, computer device, and medium for handling WS disconnection messages. The WS disconnection message handling method in this invention is applied to a server, which includes one or more processors, a memory, and one or more applications. The one or more applications are stored in the memory and configured to be executed by the processor to implement the WS disconnection message handling method.
[0017] like Figure 1 As shown, Figure 1 This is a schematic diagram of a server architecture for a WS disconnection message processing method according to an embodiment of the present invention. The server in this embodiment integrates a WS disconnection message processing device, which includes a message caching module, a queue management module, a storage service module, a connection status monitoring module, and a message recovery module. The WS disconnection message processing device integrates a WS disconnection message processing unit and runs on the storage medium corresponding to the WS disconnection message processing method to execute the steps of the WS disconnection message processing method. The functions of each module are described below.
[0018] Message sending module: Responsible for the logic of sending WS messages.
[0019] Connection Status Monitoring Module: Monitors the WS connection status in real time. Upon detecting a WS connection loss, it immediately sends a disconnection signal to the message caching module. Simultaneously, it records the timestamp of the disconnection and information related to the currently transmitted message, such as message ID and transmission progress.
[0020] The timing wheel retry module uses Netty's TimingWheel to create a delayed task when message sending fails, and then retry after the delay time. Since the timing wheel has minimal system overhead and requires few threads and memory, it can be used to implement delayed retry tasks in a lightweight manner. After a retry failure, the message is stored in the message cache module. Netty's TimingWheel is an efficient algorithm and data structure for managing timed tasks, primarily used to solve scheduling problems for massive delayed tasks (such as timeout control and heartbeat detection). It distributes tasks across different time slots (Buckets) using a layered timing wheel to reduce scheduling complexity and achieve O(1) time operation efficiency.
[0021] Message caching module: Upon receiving a connection disconnection signal, it caches unsent messages and subsequent new messages (while the connection is not restored) in a local memory queue. To ensure message order, a First-In, First-Out (FIFO) queue structure is used. When caching messages, metadata information such as a unique identifier, timestamp, and sending target is added to each message.
[0022] Message Recovery Module: When the WS connection is restored, the message recovery module retrieves cached messages from the message caching module and the storage service module. First, it retrieves messages from the memory queue in sequence for sending. After all messages in the memory queue have been sent, it reads messages from the storage service module in sequence and sends them. During message sending, it ensures that messages are not sent repeatedly based on their unique identifiers and timestamps, and that they are sent to the recipient in their original order. Successfully sent messages are promptly deleted from the cache and storage to free up cache resources.
[0023] Understandable, Figure 1 The WS client in the specific application scenario of the WS disconnection message processing method shown, or the modules contained in the WS disconnection message processing device, do not constitute a limitation on the embodiments of the present invention. That is, the number of functional module devices, the types of functional modules, or the communication methods, connection methods, or module divisions between various functional modules in the specific application scenario of the WS disconnection message processing method do not affect the overall implementation of the technical solution in the embodiments of the present invention, and can all be considered as equivalent substitutions or derivatives of the technical solutions claimed in the embodiments of the present invention.
[0024] The WS disconnection message processing device in this embodiment of the invention is mainly used to: design a caching queue mechanism to cache and store at least one of the failed transmissions and new messages when the WS disconnects; and resume message transmission in order after the WS connection is restored, ensuring the integrity and sequence of messages received by the WS client, thereby improving server stability and user experience. Specifically, it avoids directly discarding messages when the WS disconnects, ensuring that messages are accurately sent to the WS client after the connection is restored. This embodiment of the invention can provide sufficient caching capacity without utilizing the limited local cache of the WS client, supports large-scale message storage, and can adapt to the needs of different business scenarios.
[0025] Those skilled in the art will understand that Figure 1 The server architecture shown is merely one application scenario of the present invention and does not constitute a limitation on the application scenarios of the present invention.
[0026] Figure 2This is a flowchart illustrating the WS disconnection message processing method provided in an embodiment of the present invention. The method is applied to a message processing engine, where at least one WS client is bound to the same account, and each WS client establishes a WS connection with the message processing engine. A first WS client establishes a WS connection with the message processing engine; this first WS client can be an application used for real-time chat, online games, financial data, government Q&A, etc. Figure 2 As shown, the method includes the following steps S110-S150.
[0027] S110, Receive the first message.
[0028] The first message is generated by the message sending module in the message processing engine and sent to the first WS client, and is a message indicating that the WS connection failed to be sent.
[0029] S120. Based on the queried pre-stored WS connection information, forward the first message to the first WS client.
[0030] S130. When an abnormal WS connection is detected, the first message and the second message are cached according to the message generation timestamp.
[0031] The second message is generated by the message sending module in the message processing engine and sent to the first WS client, but not sent after the first message. That is, the first message is a message that failed to be sent after a WS connection error, and the second message is a new message that appears after the WS connection error and the first message failed to be sent.
[0032] In one embodiment, step S130 includes: Add metadata to the first message and the second message respectively. The metadata includes message identifier, message generation timestamp, and sending object. The first message and the second message are cached according to a first-in, first-out (FIFO) strategy.
[0033] In this embodiment, when persistently storing the first and second messages, an embedded database can be used to store them on the device's local disk. The data structure adopted is as follows: each message records three key pieces of information: a globally unique, monotonically increasing sequence number (similar to a tracking number), the message content itself (the contents of the package), and the current number of retries (the number of delivery attempts). During persistent storage, a "write-ahead log" technique can be used to ensure that data is not lost even in the event of a sudden power outage.
[0034] In this embodiment, by adding corresponding metadata to the first message and the second message respectively, and the metadata can distinguish the generation order between the first message and the second message, the first message and the second message can be cached based on the first-in-first-out strategy. This ensures that after the WS connection is restored, the message can be sent according to the generation timestamp, thereby avoiding message out-of-order occurrence in the first WS client and after synchronization to the second WS client.
[0035] In one embodiment, prior to step S130, the method further includes: Once it is determined that the first message failed to be sent, a delayed task corresponding to the first message is added to the time wheel; The first message is resent to the first WS client based on the time wheel's delayed task; If resending fails, the first message is cached according to the message generation timestamp.
[0036] For example, using Netty's TimingWheel, a delayed task is created when message sending fails. Once the delay time arrives, a delayed retransmission task is performed. If the retransmission fails, the message is stored in the message cache module. During caching, a first-in, first-out (FIFO) queue structure is used to ensure message order, and each message is accompanied by metadata information such as a unique identifier, timestamp, and sending target.
[0037] In this embodiment, a combination of memory queues and distributed storage can be used to ensure message caching efficiency while providing large-capacity storage support. Specifically, the memory queue is used to quickly cache failed retransmission messages, while the distributed storage is used to persistently store a large number of messages (e.g., the first message, the second message) after a WS connection failure, thereby ensuring that messages (e.g., the first message, the second message) are not lost during the WS connection disconnection and that messages are properly processed in the first instance. Subsequently, after the WS connection is restored, the message recovery process can be initiated promptly to achieve rapid message recovery and retransmission.
[0038] In one embodiment, write optimization and overflow control can also be performed on the memory queue. Specifically, such as... Figure 4 As shown, this method also includes: S310. Cache the first message and the second message according to a preset write strategy; S320. When the remaining space in the time wheel is detected to be less than a preset threshold, determine whether there is a key message in the first message and the second message. S330. If it exists, then the persistent storage of the first or second message as the key message is triggered.
[0039] Regarding write optimization, batch processing can be implemented. For example, a batch write can be triggered every 50 accumulated messages or after a 10ms delay (whichever comes first). A time wheel, i.e., a circular buffer queue, can be used to allocate a fixed area in memory to cache messages after the WS connection is lost, allowing new messages to be written to the memory queue with a microsecond delay. Direct memory access can also be used to avoid repeated copying of data between the JVM heap and outside the JVM. Regarding overflow control, when the remaining space in the memory queue is less than 20%, non-critical messages (such as incremental updates in market data pushes) can be discarded first. If the first or second message is a critical message (such as a traded order), persistent storage should be forcibly triggered, prioritizing the storage of important messages.
[0040] In this embodiment, a circular buffer queue is used to write new messages to the memory queue, ensuring real-time processing of the latest messages. Furthermore, when the memory queue reaches a preset threshold, batch message persistence is automatically triggered, and distributed log storage is employed to ensure storage capacity for massive amounts of messages during WS disconnection.
[0041] In one embodiment, such as Figure 3 As shown, after step S130 and before step S150, steps S210-S240 are also included: S210. Detect WS connection status based on backoff algorithm.
[0042] The time interval for each detection is increased by one random jitter from the time of the previous detection.
[0043] For example, the WS connection status is detected based on the backoff algorithm as follows: if the first failure occurs, wait 0.5 seconds and retry; if the third failure occurs, wait 4 seconds and retry; if the sixth failure occurs, wait 60 seconds and retry.
[0044] Each test adds random jitter, such as ±10% random fluctuation between each interval, to prevent server overload caused by a large number of clients retrying simultaneously. The test can be terminated when more than 10 retries or a total time exceeds 5 minutes, and then transferred to a dead letter queue for manual processing.
[0045] S220. After a successful retry based on the backoff algorithm, a third message is received from the first WS client, and a first confirmation response based on the third message is sent to the first WS client.
[0046] S230: Receive a second confirmation response based on the first confirmation response from the first WS client.
[0047] S240. The third message is persistently stored, and a notification message is sent to the first WS client; the notification message is used to indicate that the persistence storage of the third message is complete.
[0048] In this embodiment, when persistently storing the third message, an embedded database can be used to store it on the device's local disk. The data structure adopted is as follows: each message records three key pieces of information, namely a globally unique, monotonically increasing sequence number (similar to a tracking number), the message content itself (the contents of the package), and the current number of retries (the number of delivery attempts).
[0049] In this embodiment, WS messages are not lost by retrying through local breakpoint retry and WS connection recovery.
[0050] S140. After detecting that the WS connection has been restored to normal, query the network cache unit for the first message and the second message that were not sent to the first WS client.
[0051] S150. Send the first message and the second message to the first WS client in sequence according to the message generation timestamp.
[0052] For example, when the network is restored, the client and server will have a conversation like this: Client: "The last valid message number I received was 100. Please send me all the ones after that"; Server: "Okay, now sending messages 101-200" (sending in batches); Client: "Received 101-200. Please send messages after 201"; Server: "All messages have been resent".
[0053] Understandably, on the first WS client side, a deduplication mechanism can be further designed to address the message duplication problem that may occur after the WS connection is restored; and a buffer sorting mechanism can be used to address the message order disorder problem that may occur after the WS connection is restored. For example, for this deduplication mechanism, the client would maintain a "recent message fingerprint database," similar to human short-term memory, to determine whether a message has already been processed. Server-side verification: The server also records the message ID most recently processed by each client, rejecting duplicate submissions. For this buffering and sorting mechanism, the first WS client sets up a smart buffer pool, sorting messages received from the server by number before processing them together. For example, if message number 103 is received first, it will be temporarily stored in the buffer, and processed in order only after message number 102 arrives. This avoids message order disorder issues after the WS connection is restored. If a message is missing, the client proactively requests a resend from the server. For example, if a message is detected as not arriving for more than 5 seconds, a resend request will be automatically sent to the server.
[0054] In one embodiment, after step S150, the method further includes: Identify a second WS client that has a synchronization association with the first WS client; After sending the first message and the second message to the first WS client in sequence according to the message generation timestamp, the cached first message and second message are synchronized to the second WS client.
[0055] Specifically, in a multi-client scenario, when one client restores its WS connection and sends a message, the storage service module synchronizes relevant information about that message (such as message ID, content summary, timestamp, etc.) to the cache queues of other clients. Then, when other clients restore their connections again, they adjust their local cache queues based on this information, ensuring message consistency across all clients.
[0056] In this embodiment, based on the aforementioned message caching strategy triggered after WS disconnection, the orderly storage and management of cached messages, and the orderly sending of messages after WS connection is restored, a multi-client message synchronization mechanism can be used to achieve message cache synchronization between multiple clients, ensuring that users obtain consistent messages on different devices.
[0057] In one embodiment, such as Figure 5 As shown, step S150 includes: S151. Send the first message and the second message to the first WS client in sequence according to the message generation timestamp.
[0058] S152, Receive a resend request from the first WS client.
[0059] S153. In response to the resend request, locate the message missing interval of the first WS client from the cache based on the message generation timestamp and displacement index.
[0060] S154. Send the message corresponding to the missing message interval to the first WS client.
[0061] Each message carries a version number from the distributed storage at the time of writing.
[0062] S155. Receive an acknowledgment receipt from the first WS client.
[0063] The confirmation receipt is sent by the first WS client after processing the resent message. In particular, when the resent message is a critical message, version number verification is required to ensure message consistency.
[0064] For example, incremental reissue can be initiated when a financial app (such as a stock trading software) encounters the following situations: 1) Network intermittent recovery, i.e., re-establishing the WS connection after it is disconnected; 2) Message continuity interruption, i.e. the received message sequence numbers are not consecutive (e.g., 100 and 102 have been received, but 101 is missing). 3) Actively requesting a reissue, i.e., the user manually clicks the "Refresh Market Data" button.
[0065] When the server retrieves relevant messages from the memory queue, it can use a combination of Kafka and Redis for querying, which can optimize the retrieval index.
[0066] In this embodiment, data synchronization is performed during WS disconnection recovery, for example through incremental resending process and version number verification, to ensure that the integrity of each message in the distributed storage can be maintained.
[0067] As can be seen, the implementation of this method effectively avoids message loss when the WS disconnects through message caching, storage, and recovery mechanisms, ensuring message integrity and improving service reliability.
[0068] Figure 6 This is a schematic block diagram of a WS disconnection message processing device provided in an embodiment of the present invention. Figure 6 As shown, corresponding to the above-described WS disconnection message processing method, the present invention also provides a WS disconnection message processing apparatus 100. This WS disconnection message processing apparatus 100 includes a unit for executing the above-described WS disconnection message processing method. Please refer to... Figure 6 The WS disconnection message processing device 100 includes: a transceiver unit 110, a processing unit 120, and a storage unit 130.
[0069] The transceiver unit 110 is used to receive a first message; wherein the first message is generated by the message sending module in the message processing engine and sent to the first WS client, and is a message that failed to be sent after a WS connection error; Processing unit 120 is used to forward a first message to the first WS client through the transceiver unit 110 based on the queried pre-stored WS connection information; when a WS connection abnormality is detected, the first message and the second message are cached according to the message generation timestamp; the second message is a message generated by the message sending module in the message processing engine and sent to the first WS client, and is a message that has not been sent after the first message; The processing unit 20 is further configured to, after detecting that the WS connection has been restored to normal, query the network cache unit for the first message and the second message that have not been sent to the first WS client; and send the first message and the second message to the first WS client sequentially through the transceiver unit 110 according to the message generation timestamp.
[0070] In one embodiment, the processing unit 120 is specifically used to add metadata to the first message and the second message respectively, the metadata including message identifier, message generation timestamp and sending object; The first message and the second message are cached according to a first-in, first-out (FIFO) strategy.
[0071] In this embodiment, by adding corresponding metadata to the first message and the second message respectively, and the metadata can distinguish the generation order between the first message and the second message, the first message and the second message can be cached based on the first-in-first-out strategy. This ensures that after the WS connection is restored, the message can be sent according to the generation timestamp, thereby avoiding message out-of-order occurrence in the first WS client and after synchronization to the second WS client.
[0072] In some embodiments, the processing unit 120 is further configured to: Once it is determined that the first message failed to be sent, a delayed task corresponding to the first message is added to the time wheel; Based on the time wheel, the delayed task retransmits the first message to the first WS client through the transceiver unit 110; If resending fails, the first message is cached according to the message generation timestamp.
[0073] For example, using Netty's TimingWheel, a delayed task is created when message sending fails. Once the delay time arrives, a delayed retransmission task is performed. If the retransmission fails, the message is stored in the message cache module. During caching, a first-in, first-out (FIFO) queue structure is used to ensure message order, and each message is accompanied by metadata information such as a unique identifier, timestamp, and sending target.
[0074] In this embodiment, a combination of memory queues and distributed storage can be used to ensure message caching efficiency while providing large-capacity storage support. Specifically, the memory queue is used to quickly cache failed retransmission messages, while the distributed storage is used to persistently store a large number of messages (e.g., the first message, the second message) after a WS connection failure, thereby ensuring that messages (e.g., the first message, the second message) are not lost during the WS connection disconnection and that messages are properly processed in the first instance. Subsequently, after the WS connection is restored, the message recovery process can be initiated promptly to achieve rapid message recovery and retransmission.
[0075] In one embodiment, the processing unit 120 is further configured to: WS connection status is detected based on the backoff algorithm.
[0076] The time interval for each detection is increased by one random jitter from the time of the previous detection.
[0077] For example, the WS connection status is detected based on the backoff algorithm as follows: if the first failure occurs, wait 0.5 seconds and retry; if the third failure occurs, wait 4 seconds and retry; if the sixth failure occurs, wait 60 seconds and retry.
[0078] Each test adds random jitter, such as ±10% random fluctuation between each interval, to prevent server overload caused by a large number of clients retrying simultaneously. The test can be terminated when more than 10 retries or a total time exceeds 5 minutes, and then transferred to a dead letter queue for manual processing.
[0079] After a successful retry based on the backoff algorithm, a third message is received from the first WS client, and a first confirmation response based on the third message is sent to the first WS client.
[0080] Receive a second confirmation response based on the first confirmation response from the first WS client.
[0081] The third message is persistently stored, and a notification message is sent to the first WS client, the notification message indicating that the persistence storage of the third message is complete.
[0082] In this embodiment, when persistently storing the third message, an embedded database can be used to store it on the device's local disk. The data structure adopted is as follows: each message records three key pieces of information, namely a globally unique, monotonically increasing sequence number (similar to a tracking number), the message content itself (the contents of the package), and the current number of retries (the number of delivery attempts).
[0083] In this embodiment, WS messages are not lost by retrying through local breakpoint retry and WS connection recovery.
[0084] Understandably, on the first WS client side, a deduplication mechanism can be further designed to address the message duplication problem that may occur after the WS connection is restored; and a buffer sorting mechanism can be used to address the message order disorder problem that may occur after the WS connection is restored. For example, for this deduplication mechanism, the client would maintain a "recent message fingerprint database," similar to human short-term memory, to determine whether a message has already been processed. Server-side verification: The server also records the message ID most recently processed by each client, rejecting duplicate submissions. For this buffering and sorting mechanism, the first WS client sets up a smart buffer pool, sorting messages received from the server by number before processing them together. For example, if message number 103 is received first, it will be temporarily stored in the buffer, and processed in order only after message number 102 arrives. This avoids message order disorder issues after the WS connection is restored. If a message is missing, the client proactively requests a resend from the server. For example, if a message is detected as not arriving for more than 5 seconds, a resend request will be automatically sent to the server.
[0085] In one embodiment, the processing unit 120 is further configured to: Identify a second WS client that has a synchronization association with the first WS client; After sending the first message and the second message sequentially to the first WS client via the escalator 110 according to the message generation timestamp, the cached first message and second message are synchronized to the second WS client.
[0086] Specifically, in a multi-client scenario, when one client restores its WS connection and sends a message, the storage service module synchronizes relevant information about that message (such as message ID, content summary, timestamp, etc.) to the cache queues of other clients. Then, when other clients restore their connections again, they adjust their local cache queues based on this information, ensuring message consistency across all clients.
[0087] In this embodiment, based on the aforementioned message caching strategy triggered after WS disconnection, the orderly storage and management of cached messages, and the orderly sending of messages after WS connection is restored, a multi-client message synchronization mechanism can be used to achieve message cache synchronization between multiple clients, ensuring that users obtain consistent messages on different devices.
[0088] In one embodiment, the processing unit 120 is further configured to: The first message and the second message are cached according to a preset write strategy; When the remaining space in the time wheel is detected to be less than a preset threshold, it is determined whether there is a key message in the first message and the second message; If it exists, then the persistent storage of the first or second message, which is the key message, will be triggered.
[0089] In this embodiment, by prioritizing the persistent storage of critical messages, it is possible to ensure that critical business information is not lost, thereby maintaining business continuity.
[0090] In one embodiment, the processing unit 120 is further configured to: The first message and the second message are sent sequentially to the first WS client according to the message generation timestamp; In response to the resend request, the transceiver unit 110 locates the message missing interval of the first WS client from the cache based on the message generation timestamp and displacement index. The transceiver unit 110 sends the message corresponding to the missing message interval to the first WS client; and receives an acknowledgment from the first WS client.
[0091] As can be seen, the implementation of this device effectively avoids message loss when the WS disconnects through message caching, storage and recovery mechanisms, ensuring message integrity and improving service reliability.
[0092] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned WS disconnection message processing device and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.
[0093] The aforementioned WS disconnection message processing device can be implemented as a computer program, which can, for example... Figure 7 The method for handling WS disconnection messages is implemented on a computer device.
[0094] Please see Figure 7 , Figure 7 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. This computer device integrates any of the WS disconnection message processing devices provided in the embodiments of the present invention.
[0095] See Figure 7 The computer device includes a processor 402, a memory, and a network interface 405 connected via a system bus 401, wherein the memory may include a storage medium 403 and internal memory 404.
[0096] The storage medium 403 may store an operating system 4031 and a computer program 4032. The computer program 4032 includes program instructions that, when executed, cause the processor 402 to perform a WS disconnection message processing method.
[0097] The processor 402 provides computing and control capabilities to support the operation of the entire computer device.
[0098] The internal memory 404 provides an environment for the computer program 4032 in the storage medium 403 to run. When the computer program 4032 is executed by the processor 402, the processor 402 can execute the WS disconnection message processing method described above.
[0099] This network interface 405 is used for network communication with other devices. Those skilled in the art will understand that... Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device to which the present invention is applied. A specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0100] The processor 402 is used to run a computer program 4032 stored in the memory to perform the following steps: Receive the first message through the network interface 405; The queried pre-stored WS connection information is forwarded to the first WS client via the network interface 405 as a first message; when a WS connection abnormality is detected, the first message and the second message are cached according to the message generation timestamp; the second message is a message that has not been sent after the first message; After detecting that the WS connection has been restored, the system queries the network cache unit for the first and second messages that were not sent to the first WS client; and sends the first and second messages to the first WS client sequentially through the network interface 405 according to the message generation timestamp.
[0101] It should be understood that, in this embodiment of the invention, the processor 402 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0102] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0103] Therefore, the present invention also provides a computer-readable storage medium. This computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When executed by a processor, the program instructions cause the processor to perform the following steps: In response to a contact data authorization request, a first contact data table and a second contact data table are retrieved and stored in memory; wherein, the first contact data table includes contact numbers and the second contact data table includes contact group information; Obtain a third contact data table; wherein, the third contact data table includes contact name information; Based on the values of the first specified field in the third contact data table, the target data is obtained from the first contact data table and the second contact data table stored in memory, respectively. By combining the values of the first specified field in the third contact data table with the corresponding target data, the contact information corresponding to each contact name in the third contact data table is obtained.
[0104] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0105] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0106] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0107] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0108] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, 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 storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0109] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for WS disconnect message processing, the method is applied to a message processing engine, characterized in that, The first WS client establishes a WS connection with the message processing engine; the method comprises: receiving a first message; wherein the first message is generated by a message sending module in the message processing engine and sent to the first WS client, and is a message that has failed to be sent after a WS connection exception; forwarding the first message to the first WS client according to the queried pre-stored WS connection information; when a WS connection exception is detected, caching the first message and a second message according to a message generation timestamp; the second message is generated by a message sending module in the message processing engine and sent to the first WS client, and is a message that has not been sent after the first message; after detecting that the WS connection has returned to normal, querying the first message and the second message that have not been sent to the first WS client from a network cache unit; sending the first message and the second message to the first WS client in sequence according to the message generation timestamp.
2. The method of claim 1, wherein, The caching of the first message and the second message according to the message generation timestamp comprises: adding metadata to the first message and the second message respectively, the metadata comprising a message identifier, a message generation timestamp, and a sending object; caching the first message and the second message according to a first-in-first-out strategy.
3. The method of claim 2, wherein, Before the caching of the first message and the second message according to the message generation timestamp, the method further comprises: after determining that the first message has failed to be sent, adding a delay task corresponding to the first message to a time wheel; re-sending the first message to the first WS client based on the delay task of the time wheel; if the re-sending fails, caching the first message according to the message generation timestamp.
4. The method of claim 1, wherein, After the sending of the first message and the second message to the first WS client in sequence according to the message generation timestamp, the method further comprises: determining a second WS client that has a synchronization association with the first WS client; after the sending of the first message and the second message to the first WS client in sequence according to the message generation timestamp, synchronizing the cached first message and second message to the second WS client.
5. The method according to any one of claims 1-4, characterized in that, After the caching of the first message and the second message according to the message generation timestamp, the method further comprises: detecting a WS connection state based on a backoff algorithm, and each detection time interval is increased by 1 random jitter from the last detection time; after a successful retry based on the backoff algorithm, receiving a third message from the first WS client, and sending a first acknowledgement response based on the third message to the first WS client; receiving a second acknowledgement response based on the first acknowledgement response from the first WS client; persistently storing the third message, and sending a notification message to the first WS client; the notification message is used to indicate that the persistent storage processing of the third message is completed.
6. The method of claim 5, wherein, The caching of the first message and the second message according to the first-in-first-out strategy comprises: caching the first message and the second message according to a preset write strategy; when it is detected that the remaining space in the time wheel is less than a preset threshold, determining whether there is a key message in the first message and the second message; If present, trigger the persistent storage of the first message or the second message as a critical message.
7. The method of claim 6, wherein, The sending of the first message and the second message to the first WS client in sequence according to the message generation timestamp comprises: sending the first message and the second message to the first WS client in sequence according to the message generation timestamp; receiving a retransmission request from the first WS client; wherein the retransmission request is sent by the first WS client to the message processing engine for requesting the message timestamp and data content; in response to the retransmission request, locating the message missing interval of the first WS client from the cache according to the message generation timestamp and the displacement index; sending the messages corresponding to the message missing interval to the first WS client; receiving an acknowledgement from the first WS client.
8. A WS disconnect message processing apparatus, the apparatus is applied to a message processing engine, characterized in that, The first WS client establishes a WS connection with the message processing engine; the device comprises: a transceiving unit configured to receive a first message; wherein the first message is generated by a message sending module in the message processing engine and sent to the first WS client, and is a message that fails to be sent after a WS connection exception; a processing unit configured to forward the first message to the first WS client through the transceiving unit according to the queried pre-stored WS connection information; when a WS connection exception is detected, cache the first message and a second message according to the message generation timestamp; the second message is generated by the message sending module in the message processing engine and sent to the first WS client, and is a message that is not sent after the first message; the processing unit is further configured to query the first message and the second message that are not sent to the first WS client from the network cache unit when a WS connection is detected to be restored to normal; and send the first message and the second message to the first WS client in sequence according to the message generation timestamp through the transceiving unit.
9. A computer device, comprising: The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the WS disconnection message processing method of any one of claims 1-7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, the computer program comprises program instructions, and the program instructions can implement the WS disconnection message processing method of any one of claims 1-7 when executed by a processor.
Citation Information
Patent Citations
Reconnection methods, apparatuses and system in case of disconnection
CN105635116A
Disconnection reconnection method, device and system
CN106714334A
Message synchronization processing method and device and storage medium
CN111431964A
Game client seamless reconnection method, device and equipment in weak network environment
CN119232780A