A message synchronization method, device end and system

By employing a dual-mode interaction mechanism between the device and the server, combined with incremental rule judgment and consistency comparison, the problems of device message loss perception delay and insufficient link robustness are solved, thus achieving reliable and stable message synchronization.

CN122247962APending Publication Date: 2026-06-19LICHU BUSINESS

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
LICHU BUSINESS
Filing Date
2026-05-22
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

In existing technologies, the detection of lost device messages depends on the latest sequence number carried by the next message. This leads to increased detection time delays during off-peak periods, insufficient link robustness, and high dependence on a single messaging platform, resulting in the unavailability of the entire link.

Method used

A dual-mode interaction mechanism combining message push and calibration interaction is adopted. By maintaining local message sequence numbers, the target sequence number is obtained by interacting with the server, and incremental rule judgment or consistency comparison is performed. Combined with message content acquisition and orderly consumption within the missing range, calibration is performed using business response and active polling mechanisms.

🎯Benefits of technology

It reduces reliance on a single push messaging platform, improves the robustness and availability of the message chain, significantly reduces the latency of message loss perception during off-peak hours, and ensures the accuracy, integrity, and consistency of local sequence number status in message processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122247962A_ABST
    Figure CN122247962A_ABST
Patent Text Reader

Abstract

A message synchronization method, device, and system are disclosed, relating to the field of communication technology. The message synchronization method includes: maintaining a local message sequence number; obtaining a target sequence number through interaction with a server, where the interaction may be a message push interaction or a calibration interaction; when the judgment result is that the message does not conform to the increment rule or the comparison result is inconsistent, obtaining message content within the range from the next number of the local message sequence number to the target sequence number, consuming it, and updating the local message sequence number; when the judgment result conforms to the increment rule, consuming the corresponding message content of the message push and updating the local message sequence number; when the comparison result is consistent, keeping the local message sequence number unchanged. This invention reduces dependence on a single message push platform, effectively improving the robustness and availability of the message chain; at the same time, it significantly reduces the latency of message loss perception during off-peak business periods, ensuring the accuracy, integrity, and consistency of message processing and the status of the local sequence number.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, specifically to a message synchronization method, device, and system. Background Technology

[0002] With the rapid development of information technology in the catering industry, there are numerous business needs in catering SaaS (Software as a Service) application scenarios that require synchronizing cloud data to the device end, such as third-party delivery orders and changing store configurations through the management backend. To meet the needs of these functional scenarios, a stable message link from the cloud to the device end needs to be built to ensure that messages reach the device end accurately and in a timely manner.

[0003] In related technologies, MQTT (Message Queuing Telemetry Transport) technology is typically used to build a messaging platform. This platform uses a publish-subscribe model to achieve bidirectional communication between the cloud and the device. A typical example of this approach is the IoT (Internet of Things) platform. Due to the complexity and variability of customer production environments, there is a small probability of message loss during transmission, such as from device power outages and restarts, device process freezes, or network fluctuations on the MQTT platform. To address this, some competitors design auto-incrementing sequence numbers for messages from the cloud to the device. Upon receiving a message, the device compares its local sequence number with the sequence number of the new message. Theoretically, the sequence number follows an auto-incrementing rule. This feature allows the device to autonomously determine if a message has been lost and trigger corresponding remedial measures.

[0004] However, the existing technologies mentioned above still have the following technical problems: the detection of device message loss depends on the latest sequence number carried by the next message. During off-peak periods, due to the greatly reduced message density and slower generation of new messages, the time delay in detecting message loss increases significantly, making it impossible to detect message loss in a timely manner. In addition, the entire solution is highly dependent on the MQTT-based messaging platform. If the messaging platform malfunctions, the entire link will become unavailable, resulting in insufficient robustness of the link. Summary of the Invention

[0005] This invention provides a message synchronization method, device, and system that can solve the technical problems in the prior art, such as high latency during off-peak hours due to reliance on the next message to detect loss, and insufficient robustness of the link due to reliance on a single message platform.

[0006] In a first aspect, the present invention provides a message synchronization method applied to a device, comprising: Maintain local message sequence numbers; The target sequence number is obtained through interaction with the server. The interaction can be either a message push interaction or a calibration interaction. If the interaction is a message push interaction, it is determined whether the local message sequence number and the target sequence number conform to the increment rule. If the interaction is a calibration interaction, it is compared whether the local message sequence number and the target sequence number are consistent. When the judgment result is that it does not conform to the increment rule or the comparison result is inconsistent, the message content from the next number of the local message sequence number to the target sequence number is obtained, consumed, and the above local message sequence number is updated. When the judgment result meets the increment rule, consume the message content corresponding to the above message push and update the above local message sequence number; when the comparison result is consistent, keep the above local message sequence number unchanged.

[0007] In conjunction with the first aspect, in one implementation, obtaining the target serial number through interaction with the server specifically includes: Initiate a service request and receive a service response; extract the sequence number from the metadata area of ​​the service response as the target sequence number; or, If the conditions for active query are met, an active polling request is initiated to obtain the sequence number returned by the server, which is then used as the target sequence number.

[0008] In conjunction with the first aspect, in one implementation, before initiating an active polling request to obtain the sequence number returned by the server, the method further includes: Set the active polling timer and preset time threshold; If the above-mentioned active polling timer reaches the above-mentioned preset time threshold, it is determined that the above-mentioned active query conditions are met; When the judgment result is that it does not conform to the increment rule or the comparison result is inconsistent, it also includes: resetting the above-mentioned preset time threshold to the initial value and controlling the above-mentioned active polling timer to start timing again; When the judgment result is consistent with the increment rule or the comparison result is consistent, the method also includes: controlling the above-mentioned active polling timer to restart the timing and keeping the above-mentioned preset time threshold unchanged.

[0009] In conjunction with the first aspect, in one embodiment, the above method further includes: Record each judgment or comparison result to form a verification log; If no message loss event is recorded in the above verification log within the preset statistical period, it is determined whether the current preset time threshold has reached the maximum allowable threshold. If it is determined that it has not reached the maximum allowable threshold, the preset time threshold is increased by a preset step.

[0010] In conjunction with the first aspect, in one implementation, message content within the range from the next local message sequence number to the target sequence number is obtained and consumed, specifically including: The range from the next local message sequence number to the target sequence number is used as the range of sequence numbers to be processed, and the message content corresponding to each sequence number within the range of sequence numbers to be processed is obtained. The message content within the above-mentioned sequence number range is consumed in ascending order of sequence number.

[0011] Secondly, this invention provides a message synchronization method applied to a server, comprising: Generate a message to be sent and assign a message sequence number to the message to be sent. The message sequence number is generated according to an incrementing rule. The message to be sent and the message sequence number are sent to the device through the push channel so that the device can make an increment rule judgment. If a calibration interaction request is received from the device, the current message sequence number is returned as the target sequence number for the device to perform a consistency comparison. The receiving device sends a message content request because the judgment result does not conform to the increment rule or the comparison result is inconsistent, and returns the corresponding message content.

[0012] In conjunction with the second aspect, in one implementation, the aforementioned calibration interaction request is a business request or an active polling request; If a calibration interaction request is received from the device, the current message sequence number is returned as the target sequence number, specifically including: The receiving device sends a service request, processes the service data, generates a service response, and encapsulates the current message sequence number as the target sequence number in the metadata area of ​​the service response and returns it; or, The receiving device sends an active polling request and returns the current message sequence number as the target sequence number.

[0013] In conjunction with the second aspect, in one implementation, generating a message to be sent and assigning a message sequence number to the message to be sent specifically includes: Obtain the device's unique identifier and current date information; An increment operation is performed based on the unique identifier and the current date information. The value generated by the increment operation is used as the message sequence number and stored in association with the message content.

[0014] Thirdly, the present invention provides a device, which includes a first processor, a first memory, and a message synchronization program stored in the first memory and executable by the first processor, wherein when the message synchronization program is executed by the first processor, it implements the steps of the message synchronization method described above.

[0015] Fourthly, the present invention provides a message synchronization system, which includes the aforementioned device and server. The server includes a second processor, a second memory, and a message synchronization program stored in the second memory and executable by the second processor. When the message synchronization program is executed by the second processor, it implements the steps of the aforementioned message synchronization method.

[0016] The beneficial effects of the technical solutions provided by the embodiments of the present invention include: By adopting a dual-mode interaction mechanism combining message push and calibration interaction, the reliance on a single message push platform is reduced, effectively improving the robustness and availability of the message chain. Simultaneously, consistency comparison through calibration interaction allows devices to proactively detect message loss without waiting for the next message push, significantly reducing latency in message loss detection during off-peak hours. Furthermore, differentiated incremental rule judgment or consistency comparison is used for different interaction types, combined with message content acquisition and orderly consumption within the missing range, ensuring the accuracy, completeness, and consistency of local sequence number status in message processing. This solves the technical problems of high latency during off-peak hours due to reliance on the next message to detect loss, and insufficient robustness of the chain due to reliance on a single message platform. Attached Figure Description

[0017] Figure 1 This is a flowchart illustrating an embodiment of the message synchronization method of the present invention applied to the device side; Figure 2 This is a flowchart illustrating an embodiment of the message synchronization method of the present invention applied to the server. Figure 3 This is a flowchart illustrating a message synchronization method using message push interaction as an example in an embodiment of the present invention. Figure 4 This is a flowchart illustrating a message synchronization method using business request interaction as an example in an embodiment of the present invention. Figure 5 This is a flowchart illustrating a message synchronization method using active polling interaction as an example in an embodiment of the present invention. Detailed Implementation

[0018] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0019] In a first aspect, embodiments of the present invention provide a message synchronization method applied to a device.

[0020] In one embodiment, reference is made to Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the message synchronization method of the present invention. The message synchronization method includes: S101. Maintain local message sequence numbers; S102. Obtain the target sequence number through interaction with the server. The interaction may be a message push interaction or a calibration interaction. If the interaction is a message push interaction, determine whether the local message sequence number and the target sequence number conform to the increment rule. If the interaction is a calibration interaction, compare whether the local message sequence number and the target sequence number are consistent. S103. When the judgment result is that it does not conform to the increment rule or the comparison result is inconsistent, obtain the message content from the next number of the local message sequence number to the target sequence number, consume it, and update the above local message sequence number; S104. When the judgment result is consistent with the increment rule, consume the message content corresponding to the above message push and update the above local message sequence number; when the comparison result is consistent, keep the above local message sequence number unchanged.

[0021] In this embodiment, a local message sequence number is maintained; a target sequence number is obtained through interaction with the server, where the interaction can be either a message push interaction or a calibration interaction. If the interaction is a message push interaction, it is determined whether the local message sequence number and the target sequence number conform to an incrementing rule, i.e., whether the target sequence number is equal to the local message sequence number plus 1. If the interaction is a calibration interaction, it is compared whether the local message sequence number and the target sequence number are consistent. When the interaction is a message push interaction and the determination result is that it does not conform to the incrementing rule, or when the interaction is a calibration interaction and the comparison result is inconsistent, message content within the range from the next number of the local message sequence number to the target sequence number is obtained, consumed, and the local message sequence number is updated. When the determination result is that it conforms to the incrementing rule, the message content corresponding to the message push is consumed, and the local message sequence number is updated. When the comparison result is consistent, the local message sequence number remains unchanged.

[0022] The above method reduces reliance on a single message push platform by employing a dual-mode interaction mechanism that combines message push and calibration interaction, effectively improving the robustness and availability of the message chain. Simultaneously, by leveraging consistency comparison through calibration interaction, the device can proactively detect message loss without waiting for the next message push, significantly reducing the latency in detecting message loss during off-peak hours. Furthermore, by using incremental rule judgment or consistency comparison for different interaction types, combined with message content acquisition and orderly consumption within the missing range, the method ensures the accuracy, completeness, and consistency of local sequence number status in message processing, effectively solving the stability problem of the message chain from the server to the device.

[0023] Based on the above embodiments, in this embodiment, step S102, obtaining the target serial number through interaction with the server, specifically includes: Initiate a business request and receive a business response. Extract the sequence number from the metadata area of ​​the business response as the target sequence number. Alternatively, if the active query conditions are met, initiate an active polling request to obtain the sequence number returned by the server as the target sequence number.

[0024] In this embodiment, by providing two calibration interaction methods—service response extraction and proactive polling—the flexibility and reliability of message sequence number synchronization are achieved. Specifically, reusing the service response metadata area to transmit the sequence number enables high-frequency sequence number calibration without increasing network overhead, significantly reducing perceived latency during active service periods. Furthermore, the polling mechanism based on proactive query conditions provides a safety net for quiet service periods by adding a proactive message query mechanism to the device, limiting the maximum latency for message loss perception.

[0025] Furthermore, in one embodiment, before initiating an active polling request to obtain the sequence number returned by the server, the method further includes: First, set an active polling timer and a preset time threshold; then determine whether the active polling timer has reached the preset time threshold.

[0026] If the aforementioned active polling timer reaches the aforementioned preset time threshold, then the aforementioned active query conditions are determined to be met.

[0027] Preferably, when the judgment result is that it does not conform to the increment rule or the comparison result is inconsistent, the method further includes: resetting the preset time threshold to its initial value and controlling the active polling timer to restart timing. When the judgment result is that it conforms to the increment rule or the comparison result is consistent, the method further includes: controlling the active polling timer to restart timing while keeping the preset time threshold unchanged.

[0028] In this embodiment, by adaptively adjusting the active polling strategy based on the synchronization verification result, when message loss is detected, the preset time threshold needs to be reset to the initial value and the timer restarted, ensuring high-frequency verification and rapid recovery under abnormal conditions; while maintaining the threshold and restarting the timer when synchronization is consistent, unnecessary frequent requests are avoided, effectively reducing the communication load between the server and the device, thereby achieving a balance between system resource efficiency and link stability while ensuring the timeliness of message synchronization.

[0029] Furthermore, in one embodiment, the above message synchronization method further includes: Each judgment or comparison result is recorded to form a verification log. Cases where the judgment result does not conform to the incrementing rule or the comparison result is inconsistent are identified as message loss events. Furthermore, if a message loss event is identified and the aforementioned preset time threshold is not the initial value, the preset time threshold can be reset to its initial value.

[0030] If no message loss event is recorded in the above verification log within the preset statistical period, it is determined whether the current preset time threshold has reached the maximum allowable threshold. If it is determined that it has not reached the maximum allowable threshold, the preset time threshold is increased by a preset step. Otherwise, if it is determined that the current preset time threshold has reached the maximum allowable threshold, the preset time threshold remains unchanged.

[0031] In this embodiment, the polling strategy is adaptively optimized by dynamically adjusting the preset time threshold based on the verification log. When there are no lost events within the statistical period, the threshold is gradually increased until the maximum allowed threshold is reached, which effectively reduces the polling frequency during the stable business period and reduces the communication load and resource consumption between the server and the device.

[0032] In some embodiments, the device obtains the latest message sequence number by means of the delivery of new messages. If no new messages are received for a long time, the device will not be able to obtain the latest sequence number for calibration.

[0033] To address this issue, this embodiment utilizes a business interaction link reuse mechanism between the device and the server. By adding a digital envelope containing the latest serial number to the returned data of the business interaction, the latency of obtaining the latest serial number is reduced.

[0034] Specifically, when a device generates business data (such as order information in a catering scenario), it sends the data to the server via an application-layer communication protocol (such as HTTP). After processing the business data, the server generates a business response and encapsulates the current message sequence number in the metadata area of ​​the response (such as a custom field in the HTTP response header) and returns it to the device, forming a digital envelope. The device can then parse this metadata area to extract the target sequence number and perform calibration.

[0035] By employing a digital envelope mechanism, the latest message sequence number is encapsulated as a digital envelope in the daily business interface responses between the device and the server (e.g., encapsulated in the response header metadata area). This allows the device to obtain the latest sequence number for calibration without waiting for new message pushes. This link multiplexing method eliminates the need to establish additional network connections, thus avoiding extra network overhead and resulting in a lower overall cost. Furthermore, as device business activities increase and the frequency of business interactions between the device and the server increases, the number of message calibrations also increases, more effectively preventing message loss.

[0036] In this embodiment, to enhance the security and reliability of the message sequence number during calibration transmission and to prevent tampering or forgery, the server includes not only the message sequence number but also signature information generated based on preset rules when generating the digital envelope. Upon receiving the digital envelope, the device must first verify the validity of the signature; only after successful verification can the sequence number be extracted for business processing.

[0037] Specifically, the message format of the aforementioned digital envelope includes a serial number field and a signature field. When generating the signature, the server uses the following rules: it obtains the time field returned by the interface, the current message serial number field, and the preset device key; it concatenates these three fields in a preset order; and then uses a message digest algorithm (such as MD5) to calculate the digest of the concatenated string to generate a signature value. The server encapsulates the aforementioned serial number field and the aforementioned signature value into the header field of the business response and returns it as a digital envelope to the device.

[0038] After receiving the aforementioned service response, the device parses the header fields to obtain the serial number field and the signature field. Using the same signature rules as the server, the device recalculates the signature value based on the locally stored device key, the parsed time field, and the serial number field, and then compares the calculated signature value with the signature field.

[0039] If the comparison results are consistent, the signature verification is deemed successful, indicating that the serial number has not been tampered with and its source is trustworthy. The device will continue to perform subsequent calibration comparisons and business processing on the serial number. If the comparison results are inconsistent, the signature verification is deemed unsuccessful, indicating that the serial number may be at risk of tampering or forgery. The device will discard the serial number, not perform calibration processing, and may record a security log or trigger an alarm.

[0040] Furthermore, message calibration cannot be triggered during the silent period when there is no business interaction on the device and no new messages are generated. To completely avoid the latency problem of message verification, this embodiment also adds an active polling mechanism on the device side.

[0041] Specifically, the device maintains an active polling timer and sets a reasonable preset time threshold as the polling interval according to the business attributes (for example, 2 minutes in a catering SaaS scenario). If the device does not trigger a message verification action within the preset time threshold (including not receiving a push message and not initiating a business request), it will actively initiate a message query request and perform the verification action.

[0042] By incorporating proactive polling, the maximum perceived latency for each message can be guaranteed to remain within a preset time threshold (e.g., 2 minutes). Furthermore, since proactive polling typically employs a communication protocol (e.g., HTTP) independent of the message push platform (e.g., MQTT), the overall solution's dependence on the message push platform is reduced. Even if the message push platform malfunctions and crashes, the device can still verify messages and synchronize them through proactive polling, thereby improving overall stability.

[0043] During business development, for some devices with good network conditions and stable operation, high-frequency active polling yields little benefit and instead increases unnecessary load. For these devices, this embodiment addresses this by dynamically adjusting the polling interval to reduce the load on both the server and the device, thereby improving overall efficiency.

[0044] Specifically, the device records the results of each message sequence number verification to form a verification log. If no message loss event occurs within the first statistical period (e.g., within one day), the device increases the preset time threshold by a preset step (e.g., by 0.5 minutes), accumulating up to the maximum allowed threshold (e.g., 5 minutes). If a message loss event occurs, the preset time threshold is directly reset to its initial value (e.g., 2 minutes).

[0045] Furthermore, although this embodiment uses the catering scenario as an example, it is also applicable to other IoT scenarios that require message synchronization.

[0046] Furthermore, in one embodiment, obtaining message content within the range from the next local message sequence number to the target sequence number and performing consumption processing specifically includes: First, the range from the next local message sequence number to the target sequence number is taken as the range of sequence numbers to be processed, and the message content corresponding to each sequence number within the range of sequence numbers to be processed is obtained; wherein, for each sequence number within the range of sequence numbers to be processed, if the corresponding message content is already stored locally, it is read from the local cache, and if it is not stored locally, it is requested from the server.

[0047] Then, the message content within the above-mentioned sequence number range is consumed in ascending order of sequence number.

[0048] In this embodiment, by clearly defining the range of sequence numbers to be processed and executing consumption operations in ascending order, the integrity of message processing and the consistency of business logic order are ensured, effectively avoiding data state errors caused by missing or out-of-order messages.

[0049] Optionally, in one embodiment, in order to handle the concurrent conflict between message push and business response (or active polling) in terms of time and avoid repeated fetching or consumption of messages, the device can also maintain a message queue to be processed and record the processing status of each message in the queue.

[0050] Specifically, when the device receives a push notification from the server, it does not immediately update the locally persisted message sequence number. Instead, it adds the message sequence number corresponding to the push notification to the aforementioned message queue and marks it as "processing".

[0051] When the device obtains the target serial number through a service response or proactive polling and performs calibration and comparison, it prioritizes querying the pending message queue. The specific logic is as follows: Queue Existence Check: The device checks whether the target sequence number already exists in the message queue to be processed.

[0052] Skip processing: If the target sequence number already exists in the message queue to be processed, it means that the message corresponding to the sequence number is being processed. The device determines that there is no need to make additional message content requests or repeat consumption processing, and directly ignores this calibration trigger.

[0053] Normal calibration: If the target sequence number does not exist in the message queue to be processed, the device will perform the aforementioned comparison step (i.e., compare whether the local message sequence number is consistent with the target sequence number), and decide whether to trigger the query and consumption of missing messages based on the comparison result.

[0054] In addition, once the device finishes consuming the business corresponding to a message sequence number in the pending message queue, it removes the message sequence number from the pending message queue and updates the local message sequence number.

[0055] In other embodiments, when the device obtains the target sequence number through the service response for comparison, it not only compares the target sequence number with the local message sequence number, but also compares the target sequence number with the maximum sequence number in the message queue to be processed.

[0056] If the target sequence number is less than or equal to the maximum sequence number in the message queue to be processed, it is determined that the sequence numbers are consistent (or the message is determined not to be lost), and no message content request is triggered. If the target sequence number is greater than the local message sequence number and greater than the maximum sequence number in the message queue to be processed, it is determined that the message is lost, and the message retrieval process is triggered.

[0057] Secondly, embodiments of the present invention also provide a message synchronization method applied to a server.

[0058] In one embodiment, reference is made to Figure 2 , Figure 2 This is a schematic flowchart illustrating another embodiment of the message synchronization method of the present invention. The message synchronization method includes: S201. Generate a message to be sent and assign a message sequence number to the message to be sent. The message sequence number is generated according to an incrementing rule. S202. The message to be sent and the message sequence number are sent to the device through the push channel so that the device can make an increment rule judgment; the message sequence number is used as the target sequence number obtained by the device. S203. If a calibration interaction request is received from the device, the current message sequence number is returned as the target sequence number for the device to perform a consistency comparison; S204. When the receiving device sends a message content request because the judgment result does not conform to the increment rule or the comparison result is inconsistent, the corresponding message content is returned.

[0059] In this embodiment, the server generates an incrementing sequence number and sends it via the push channel, enabling the device to perform incrementing rule judgments and ensuring basic message synchronization efficiency. Simultaneously, by responding to calibration interaction requests and returning the latest sequence number, the device can perform consistency comparisons, allowing it to detect message loss without waiting for the next message, reducing reliance on a single push link. Furthermore, by responding to message content requests and returning missing content, the integrity and consistency of message data are guaranteed, thus collaboratively improving the reliability and stability of the overall message synchronization system from the server's perspective.

[0060] Furthermore, in one embodiment, the aforementioned calibration interaction request is a service request or an active polling request.

[0061] If a calibration interaction request is received from the device, the current message sequence number is returned as the target sequence number, specifically including: If the calibration interaction request is a business request, that is, a business request sent by the receiving device, after processing the business data, a business response is generated, and the current message sequence number is encapsulated as the target sequence number in the metadata area of ​​the above business response and returned.

[0062] If the calibration interaction request is an active polling request, that is, an active polling request sent by the receiving device, the current message sequence number is returned as the target sequence number.

[0063] In this embodiment, by distinguishing between two calibration interaction forms—business requests and proactive polling requests—flexible adaptation of the sequence number return strategy is achieved.

[0064] Furthermore, in one embodiment, generating a message to be sent and assigning a message sequence number to the message to be sent specifically includes: First, obtain the device's unique identifier and current date information; Then, based on the unique identifier and the current date information, an increment operation is performed, and the value generated by the increment operation is used as the message sequence number and stored in association with the message content.

[0065] In this embodiment, a message sequence number is generated by performing an auto-increment operation by combining the device's unique identifier with the current date information. This ensures the uniqueness and strict incremental order of the sequence number at the device level, providing a reliable data foundation for the device to perform increment rule judgment. At the same time, resetting the count based on the date information avoids the infinite growth of the sequence number value, which is beneficial for data sharding storage and historical message management.

[0066] like Figure 3 As shown, taking the message push interaction between the device and the server as an example, the message synchronization method in this embodiment specifically includes: A1. The server detects a change in business data and triggers a message push process; A2. Query and confirm the devices that need to be pushed; A3. Generate message sequence numbers using Redis auto-incrementing based on the device's unique identifier and the current message date; A4. Associate the stored message content, device unique identifier, message date, and message sequence number; A5. Send an IoT message to the device, which carries the message content, message date, and message sequence number; A6. The device receives IoT messages and parses them to obtain the message content and message sequence number; A7. Determine whether the current message sequence number conforms to the incrementing rule with the locally maintained local message sequence number; if yes, the result is that it conforms to the incrementing rule, then proceed to A10; if no, the result is that it does not conform to the incrementing rule, then proceed to A8.

[0067] A8. The device iterates through the missing message sequence numbers and determines that the message content corresponding to the missing message sequence number is lost; A9. Query the corresponding message content based on the missing message sequence number and consume it for business purposes; at this point, the missing message can be filled in, so that the latest message can be consumed and processed in subsequent steps. A10. The device consumes the latest message content and performs business processing.

[0068] like Figure 4As shown, taking the interaction of business requests between the device and the server as an example, the message synchronization method in this embodiment specifically includes: B1. The device initiates a business request by calling the business interface. The above business requests include order submission requests or product query requests, etc. B2. The server receives business requests and processes the corresponding business data. B3. After the business process is completed, the server adds a digital envelope with the current maximum message sequence number through a unified filter and encapsulates the digital envelope into the header field of the business response; this current maximum message sequence number is the target sequence number. B4. The device receives the service response, processes the corresponding business logic, and obtains the target sequence number; B5. Determine if the local message sequence number matches the target sequence number; if yes, proceed to B6; otherwise, proceed to B7.

[0069] B6. Determine that no message is missing, do not process the message, keep the local message sequence number unchanged, and proceed to B10.

[0070] B7. Traverse through the missing message sequence numbers and determine if the message corresponding to the missing message sequence number has been lost; B8. Retrieve the corresponding message content based on the missing message sequence number and message date; B9. Consume the missing message content and update the local message sequence number; B10. After completing the calibration of the latest message sequence number, reset the local active polling timer to reduce unnecessary queries.

[0071] like Figure 5 As shown, taking the active polling interaction between the device and the server as an example, the message synchronization method in this embodiment specifically includes: C1. The device determines whether the count value of the active polling timer has reached the preset time threshold; if so, it proceeds to C2; otherwise, it proceeds to C1.

[0072] C2. Obtain the latest serial number by calling the server interface via an HTTP request, and use it as the target serial number; C3. Determine if the local message sequence number is consistent with the latest sequence number; if yes, proceed to C4; otherwise, proceed to C5.

[0073] C4. Determine that no message is missing, do not process the message, keep the local message sequence number unchanged, and proceed to C8.

[0074] C5. Traverse through the missing message sequence numbers and determine if the message corresponding to the missing message sequence number has been lost; C6. Query the corresponding message content based on the missing message sequence number and message date; at this time, if the preset time threshold is not the initial value, the preset time threshold can be reset to the initial value; C7. Consume the missing message content and update the local message sequence number; C8. Reset the active polling timer and jump to C1.

[0075] In addition, if message sequence number verification is triggered in other business interaction logic, the active polling timer will be reset. If no message loss event occurs within the preset statistical period, the preset time threshold will be increased.

[0076] In this embodiment, by supplementing the message push platform with message sequence number verification, digital envelope mechanism, and device proactive polling strategy as described above, the robustness of the overall link is improved. While enhancing the business data synchronization experience, the overall communication cost is effectively controlled.

[0077] Thirdly, embodiments of the present invention provide a device, which includes a first processor, a first memory, and a message synchronization program stored in the first memory and executable by the first processor. When the message synchronization program is executed by the first processor, it implements the steps of the message synchronization method described in the first aspect. In this embodiment, the device may be a terminal device with data processing capabilities, such as a personal computer (PC) or a laptop computer.

[0078] Fourthly, embodiments of the present invention provide a message synchronization system, which includes the aforementioned device and server. The server includes a second processor, a second memory, and a message synchronization program stored in the second memory and executable by the second processor. When the message synchronization program is executed by the second processor, it implements the steps of the message synchronization method described in the second aspect. In this embodiment, the server can be a device with data processing capabilities, such as a personal computer (PC) or a server.

[0079] The aforementioned device or server may include a processor, memory, communication interface, and communication bus.

[0080] The communication bus can be of any type and is used to interconnect the processor, memory, and communication interface.

[0081] Communication interfaces include input / output (I / O) interfaces, physical interfaces, and logical interfaces used for interconnecting devices within the device, as well as interfaces used for interconnecting the device with other devices (such as other computing devices). Physical interfaces can be Ethernet interfaces, fiber optic interfaces, ATM interfaces, etc.; user equipment can be displays, keyboards, etc.

[0082] Memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.

[0083] The processor can be a general-purpose processor, which can call a message synchronization program stored in memory and execute the message synchronization method provided in this embodiment of the invention. For example, the general-purpose processor can be a central processing unit (CPU). The method executed when the message synchronization program is called can be referred to in various embodiments of the message synchronization method of this invention, and will not be repeated here.

[0084] Those skilled in the art will understand that the above hardware structure does not constitute a limitation of the present invention, and may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.

[0085] It should be noted that the sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0086] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such processes, methods, products, or apparatus. The terms "first," "second," and "third," etc., are used to distinguish different objects, etc., and do not indicate a sequence, nor do they limit "first," "second," and "third" to different types.

[0087] In the description of the embodiments of the present invention, terms such as "exemplary," "for example," or "for instance" are used to indicate that they are examples, illustrations, or descriptions. Any embodiment or design that is described as "exemplary," "for example," or "for instance" in the embodiments of the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of terms such as "exemplary," "for example," or "for instance" is intended to present the relevant concepts in a specific manner.

[0088] In the description of the embodiments of the present invention, unless otherwise stated, " / " means "or". For example, A / B can mean A or B. "And / or" in the text is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in the description of the embodiments of the present invention, "multiple" means two or more.

[0089] In some processes described in the embodiments of the present invention, multiple operations or steps are included in a specific order. However, it should be understood that these operations or steps may not be executed in the order they appear in the embodiments of the present invention, or may be executed in parallel. The sequence number of the operation is only used to distinguish different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed sequentially or in parallel, and these operations or steps may be combined.

[0090] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of the present invention.

[0091] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A message synchronization method, applied to a device, characterized in that, The method includes: Maintain local message sequence numbers; The target sequence number is obtained through interaction with the server, wherein the interaction is a message push interaction or a calibration interaction; wherein, if the interaction is a message push interaction, it is determined whether the local message sequence number and the target sequence number conform to the increment rule; if the interaction is a calibration interaction, it is compared whether the local message sequence number and the target sequence number are consistent. When the judgment result is that it does not conform to the increment rule or the comparison result is inconsistent, the message content from the next number of the local message sequence number to the target sequence number is obtained, consumed, and the local message sequence number is updated. When the judgment result meets the increment rule, consume the message content corresponding to the message push and update the local message sequence number; when the comparison result is consistent, keep the local message sequence number unchanged.

2. The message synchronization method as described in claim 1, characterized in that, The step of obtaining the target serial number through interaction with the server specifically includes: Initiate a service request and receive a service response, extracting the sequence number from the metadata area of ​​the service response as the target sequence number; or, If the conditions for active query are met, an active polling request is initiated to obtain the sequence number returned by the server, which is then used as the target sequence number.

3. The message synchronization method as described in claim 2, characterized in that, Before initiating an active polling request to obtain the sequence number returned by the server, the following steps are also included: Set the active polling timer and preset time threshold; If the active polling timer reaches the preset time threshold, it is determined that the active query condition is met; When the judgment result is that it does not conform to the increment rule or the comparison result is inconsistent, the method further includes: resetting the preset time threshold to the initial value and controlling the active polling timer to restart the timing. When the judgment result is consistent with the increment rule or the comparison result is consistent, the method further includes: controlling the active polling timer to restart the timing and keeping the preset time threshold unchanged.

4. The message synchronization method as described in claim 3, characterized in that, The method further includes: Record each judgment or comparison result to form a verification log; If the verification log does not record a message loss event within the preset statistical period, it is determined whether the current preset time threshold has reached the maximum allowable threshold. If it is determined that it has not reached the maximum allowable threshold, the preset time threshold is increased by a preset step.

5. The message synchronization method as described in claim 1, characterized in that, Retrieve message content from the next local message sequence number to the target sequence number, and process it for consumption. Specifically, this includes: Using the range from the next local message sequence number to the target sequence number as the range of sequence numbers to be processed, the message content corresponding to each sequence number within the range of sequence numbers to be processed is obtained; The message content within the range of the sequence numbers to be processed is consumed in ascending order of sequence number.

6. A message synchronization method, applied to a server, characterized in that, The method includes: Generate a message to be sent and assign a message sequence number to the message to be sent, wherein the message sequence number is generated according to an incrementing rule; The message to be sent and the message sequence number are sent to the device through the push channel so that the device can make an increment rule judgment. If a calibration interaction request is received from the device, the current message sequence number is returned as the target sequence number for the device to perform a consistency comparison. The receiving device sends a message content request because the judgment result does not conform to the increment rule or the comparison result is inconsistent, and returns the corresponding message content.

7. The message synchronization method as described in claim 6, characterized in that, The calibration interaction request can be a business request or an active polling request. If a calibration interaction request is received from the device, the current message sequence number is returned as the target sequence number, specifically including: The receiving device sends a service request, processes the service data, generates a service response, and encapsulates the current message sequence number as the target sequence number into the metadata area of ​​the service response and returns it; or, The receiving device sends an active polling request and returns the current message sequence number as the target sequence number.

8. The message synchronization method as described in claim 6, characterized in that, Generating a message to be sent and assigning a message sequence number to the message to be sent specifically includes: Obtain the device's unique identifier and current date information; An increment operation is performed based on the unique identifier and the current date information. The value generated by the increment operation is used as the message sequence number and stored in association with the message content.

9. A device terminal, characterized in that, The device includes a first processor, a first memory, and a message synchronization program stored in the first memory and executable by the first processor, wherein when the message synchronization program is executed by the first processor, it implements the steps of the message synchronization method as described in any one of claims 1 to 5.

10. A message synchronization system, characterized in that, The device and server as described in claim 9 are included, wherein the server includes a second processor, a second memory, and a message synchronization program stored in the second memory and executable by the second processor, wherein when the message synchronization program is executed by the second processor, it implements the steps of the message synchronization method as described in any one of claims 6 to 8.