Message merging method and device, electronic equipment and storage medium
By obtaining the geographical information of the device and counting the number of message receptions on the MQTT agent, the message combined sending mode is determined and triggered, which solves the problem of increased network load and processing pressure in communication between IoT devices, and realizes the optimized sending and delivery of high-frequency messages. Network performance improvements.
Patent Information
- Application Number
- CN202410984879.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-08
AI Technical Summary
The development of IoT technology has led to frequent communication between devices, resulting in increased network load and MQTT broker processing pressure. Existing methods fail to make full use of device location and time information to optimize message sending.
During the communication process between the MQTT agent and the MQTT client, the geographical information of the device and the number of statistical message receptions are obtained, the message merge sending mode is determined whether to be triggered, the target control instruction is generated, and the merge message is sent to the client to achieve message merge.
Optimize high-frequency message sending through message merging, reduce network load and MQTT Broker processing pressure, and improve network performance and system response speed.
Smart Images

Figure CN118748688A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a message merging method and device, electronic equipment, and storage medium. Background Art
[0002] With the development of IoT technology, communication between devices is becoming more frequent, resulting in increasing network load and MQTT proxy processing pressure. High-frequency message sending not only takes up a lot of network resources, but may also cause performance bottlenecks. Although some methods have been tried to optimize message sending, they often lack full utilization of device geographic location and time information. Summary of the invention
[0003] In view of the above problems, a message merging method and device, electronic device, and storage medium are proposed to overcome the above problems or at least partially solve the above problems.
[0004] A first aspect of the present invention provides a message merging method, which is applied to an MQTT agent, and the method comprises:
[0005] During the communication between the MQTT proxy and the MQTT client, the device geographic information is obtained, the messages sent by the MQTT client are counted, and the number of messages received per unit time is obtained;
[0006] Determining whether to trigger the message merge sending mode based on the device geographic information and the number of messages received within the unit time;
[0007] When it is determined that the message merging sending mode is triggered, generating a target control instruction for turning on the message merging mode;
[0008] Sending the target control instruction to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message;
[0009] Receive the merged message sent by the MQTT client.
[0010] A second aspect of the present invention provides a message merging method, which is applied to an MQTT client, and the method comprises:
[0011] During the communication between the MQTT proxy and the MQTT client, sending device geographic information and transmission messages to the MQTT proxy;
[0012] Receiving a target control instruction sent by the MQTT proxy for turning on a message merging mode, the target control instruction being generated when the MQTT proxy determines to trigger the message merging sending mode based on the device geographic information and the number of messages received per unit time, the number of messages received per unit time being determined by counting messages sent by the MQTT client;
[0013] Merging multiple messages to be sent based on the target control instruction to obtain a merged message;
[0014] The merged message is sent to the MQTT proxy.
[0015] A third aspect of the present invention provides a message merging device, applied to an MQTT proxy, the device comprising:
[0016] A data acquisition module, used to acquire device geographic information, count messages sent by the MQTT client, and obtain the number of messages received per unit time during the communication between the MQTT proxy and the MQTT client;
[0017] A trigger judgment module, used to judge whether to trigger the message merge sending mode based on the device geographic information and the number of message receptions within the unit time;
[0018] A target control instruction generating module, used for generating a target control instruction for starting the message merging mode when it is determined that the message merging sending mode is triggered;
[0019] A target control instruction sending module, used for sending the target control instruction to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message;
[0020] The merged message receiving module is used to receive the merged message sent by the MQTT client.
[0021] A fourth aspect of the present invention provides a message merging device, applied to an MQTT client, the device comprising:
[0022] A data sending module, used to send device geographic information and transmission messages to the MQTT proxy during the communication between the MQTT proxy and the MQTT client;
[0023] A target control instruction receiving module, used to receive a target control instruction sent by the MQTT agent to enable a message merging mode, wherein the target control instruction is generated by the MQTT agent when the message merging sending mode is triggered based on the device geographic information and the number of messages received per unit time, wherein the number of messages received per unit time is determined by counting the messages sent by the MQTT client;
[0024] A message merging module, used to merge multiple messages to be sent based on the target control instruction to obtain a merged message;
[0025] The merged message sending module is used to send the merged message to the MQTT agent.
[0026] A fifth aspect of the present invention provides an electronic device, comprising a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the message merging method as described above when executed by the processor.
[0027] A sixth aspect of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the message merging method described above is implemented.
[0028] The embodiments of the present invention have the following advantages:
[0029] The embodiment of the present invention obtains device geographic information and counts messages sent by the MQTT client during the communication process between the MQTT proxy and the MQTT client, thereby obtaining the number of message receptions per unit time; then determines whether to trigger the message merge sending mode based on the device geographic information and the number of message receptions per unit time; when determining to trigger the message merge sending mode, a target control instruction for turning on the message merge mode can be generated; then the target control instruction is sent to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message; and the merged message sent by the MQTT client is received, thereby achieving the goals of optimizing the sending of high-frequency messages and reducing network load and MQTT Broker (MQTT Broker is a key component in the MQTT protocol, responsible for receiving messages from MQTT clients and distributing these messages to other MQTT clients that have subscribed to corresponding topics) processing pressure. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0031] Figure 1 is a flow chart of the steps of a message merging method provided by one embodiment of the present invention;
[0032] Figure 2 is a flowchart of another message merging method provided by an embodiment of the present invention;
[0033] Figure 3 This is a schematic diagram of a message merging process provided by an embodiment of the present invention;
[0034] Figure 4 It is a structural diagram of a message merging device provided by an embodiment of the present invention;
[0035] Figure 5 It is a structural diagram of a message merging device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0037] Reference Figure 1 , shows a flow chart of the steps of a message merging method provided by an embodiment of the present invention, which is applied to an MQTT (Message Queuing Telemetry Transport) agent, and may specifically include the following steps:
[0038] Step S101, during the communication between the MQTT proxy and the MQTT client, obtaining the device geographic information of the MQTT client, counting the messages sent by the MQTT client, and obtaining the number of messages received per unit time;
[0039] The device geographic information may include but is not limited to obtaining the device's latitude and longitude, speed, direction, etc. The device geographic information in the embodiment of the present invention may be real-time geographic data.
[0040] During the communication between the MQTT agent and the MQTT client, the MQTT client can send messages to the MQTT agent. A counter can be set in the MQTT agent to count the total number of received messages. The messages received in the MQTT agent are the messages sent by the MQTT client. At the same time, a timer is set for time statistics, so that the number of messages received per unit time can be calculated.
[0041] Specifically, the MQTT proxy is connected to the MQTT client, and two-way communication can be performed between the MQTT proxy and the MQTT client, that is, the MQTT proxy sends data to the MQTT client, and / or the MQTT client sends messages to the MQTT proxy.
[0042] In one embodiment of the present invention, the MQTT proxy can receive device geographic information sent by the MQTT client; in the process of receiving the message sent by the MQTT client, the message sending time of the message sent by the MQTT client is obtained, and the total number of message receptions can also be counted in the MQTT proxy; the time interval of the message sending time and the number of message receptions per unit time of the total number of message receptions are calculated.
[0043] Among them, wireless connection can be used between the MQTT agent and the MQTT client, such as Wi-Fi, Bluetooth, 4G / 5G and other wireless connection methods.
[0044] After the connection is established between the MQTT proxy and the MQTT client, the MQTT client can obtain the device's latitude, longitude, speed, direction and other geographic location information in real time through the GPS positioning module or the network positioning module. And during the message receiving process, the timestamp of the device sending the message can be recorded to determine the time when the new message was sent.
[0045] Then, each time the MQTT agent receives a message, the cumulative number of messages increases by 1. After a period of data transmission, the number of messages received per unit time can be calculated based on the timestamp and the number of messages received. That is, the number of messages received per unit time = number of messages received / statistical time.
[0046] Step S102, judging whether to trigger the message merge sending mode based on the device geographic information and the number of messages received per unit time;
[0047] After obtaining the device geographic information and the messages per unit time in the MQTT agent, it can be determined whether the message merge mode will be triggered based on these two data. The message merge mode is a preset mode for merging and sending multiple messages in a preset format. The preset format can be set according to the actual scenario requirements, and there is no excessive restriction on this in the embodiments of the present invention.
[0048] Specifically, judging whether to trigger the message merge sending mode based on the device geographic information and the number of messages received per unit time may include: determining the number of messages received by each device in a preset area per unit time based on the device geographic information; when the number of messages received by the target device per unit time is greater than the preset number of messages received, determining that the target device is a device that frequently sends messages in the preset area; counting the number of devices that frequently send messages; judging whether the number of devices is greater than a preset device number threshold; and determining to trigger the message merge sending mode when the number of devices is greater than the preset device number threshold.
[0049] In an embodiment of the present invention, the MQTT proxy can determine the area where each MQTT client is located based on the acquired device geographic information, and then determine the number of messages received by multiple devices in the same area per unit time, count the number of devices greater than a preset number of receptions per unit time (i.e., the number of devices that frequently send messages), and then compare the number of devices with a preset device number threshold. When the number of devices is greater than the preset device number threshold, it is determined that there are a large number of frequently sending devices in the same area, and the message merge sending mode can be triggered.
[0050] Among them, the preset area, preset receiving number and device quantity threshold in the embodiment of the present invention can be set according to the actual scenario.
[0051] In one embodiment of the present invention, in the MQTT proxy, pre-processing may also be performed on the received data (such as device geographic information and the number of received messages within the unit time).
[0052] The preprocessing process in the embodiment of the present invention may include but is not limited to a data cleaning stage, a format conversion stage, an outlier processing stage, etc. In the data cleaning stage, the module removes duplicate, erroneous or invalid data; in the format conversion stage, the module converts the data into a unified format for subsequent analysis; in the outlier processing stage, the module identifies and processes abnormal data to ensure the accuracy and reliability of the data.
[0053] In another embodiment of the present invention, in the MQTT proxy, the data obtained after preprocessing can be analyzed, specifically, the analysis can be performed based on the geographical location and time information of the device. The mobile state of the device can be determined by calculating parameters such as the moving speed, acceleration, and direction change of the device. It can then be determined whether there is a need for message merging, and a corresponding message merging strategy can be formulated. The strategy can include the time window, geographical range, message type, etc. of the merge, and can be dynamically adjusted according to actual needs.
[0054] For example, when the device's geographic location has not changed, the geographic location will not change. For this type of message, the MQTT client will send it in the form of a merged message.
[0055] Step S103, when it is determined that the message merge sending mode is triggered, a target control instruction for starting the message merge mode is generated;
[0056] When the MQTT proxy determines to trigger the message merge sending mode, it can generate a target control instruction, which can be used to control the MQTT client to start the merge mode.
[0057] Step S104, sending a target control instruction to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message;
[0058] The MQTT proxy can send target control instructions to the MQTT client. After receiving the target control instructions, the MQTT client can merge multiple messages to be published to obtain a merged message to reduce the amount of data transmission.
[0059] Step S105, receiving the merge message sent by the MQTT client.
[0060] In one embodiment of the present invention, it can be determined whether the message sent by the MQTT client is a merged message; when it is determined that the message sent by the MQTT client is a merged message, the merged message is parsed using a preset merged message format.
[0061] The preset merged message format can be set according to the actual scenario, and there is no excessive restriction on this in the embodiment of the present invention. For example, the preset merged message format can be: merged message type + message ciphertext list, and the format of the message ciphertext list is "forwarding direction + encryption method + ciphertext".
[0062] In the embodiment of the present invention, the MQTT client may also compress and encrypt the message to be sent.
[0063] Data compression refers to reducing the space required for data storage or the time required for transmission through a preset compression algorithm. Data compression methods can be divided into two categories: lossless compression and lossy compression.
[0064] Lossless compression methods ensure that no information is lost during the compression and decompression process, and the original data can be fully restored. This type of method is suitable for scenarios such as text, code, and configuration files where no information loss is allowed. Lossless compression methods can include, but are not limited to, any one or more of the following:
[0065] Huffman Coding, Arithmetic Coding, Lempel-Ziv series algorithms, Run-Length Encoding (RLE), Deflate.
[0066] Lossy compression methods achieve higher compression ratios by discarding some unimportant information. They are suitable for multimedia data such as audio, video, and images, which are not sensitive to the loss of certain details. Lossy compression methods can include any one or more of the following:
[0067] JPEG, MP3, MPEG, AV1, WebP.
[0068] In actual applications, a matching compression method can be selected according to the data type of the combined message to be sent, the compression target (such as speed, compression ratio, and acceptable degree of quality loss), and the application scenario.
[0069] Data encryption is an important means of protecting data security. It prevents unauthorized access and leakage by converting data into an unreadable form. Data encryption methods are mainly divided into two categories: symmetric encryption and asymmetric encryption. In practical applications, symmetric encryption and asymmetric encryption can also be combined to achieve hybrid encryption.
[0070] Symmetric encryption uses the same key to encrypt and decrypt data. This method has the advantages of high speed and high efficiency, and is suitable for encrypting large amounts of data. Symmetric encryption algorithms may include, but are not limited to, any one or more of DES (Data Encryption Standard), 3DES (Triple DES), AES (Advanced Encryption Standard), and RC4.
[0071] Asymmetric encryption uses a pair of keys: a public key and a private key. The public key is used to encrypt data, and the private key is used to decrypt data. The advantage of this method is that it provides better key management, but it is slower and is suitable for encryption or key exchange of small amounts of data. Asymmetric encryption algorithms can include but are not limited to: RSA (Rivest-Shamir-Adleman), ECC (Elliptic Curve Cryptography), DSA (Digital Signature Algorithm), Diffie-Hellman.
[0072] In addition to the above encryption methods, other encryption methods may include but are not limited to hash functions, message authentication codes (MACs), and digital signatures.
[0073] In actual applications, the MQTT client can select the appropriate encryption method based on the sensitivity, application scenarios, performance requirements, and security requirements of the data to be transmitted to ensure data transmission security.
[0074] In one embodiment of the present invention, when the MQTT client is in the message merging mode, the MQTT agent determines the number of devices in a preset area whose message receiving number is greater than the preset receiving number based on the latest device geographic information and the number of message receiving per unit time, and when the device data is less than or equal to the preset device data threshold, it can be determined that the current data processing pressure is small, and a second control instruction to cancel the message merging mode can be generated, and the second control instruction can be sent to the MQTT client, so that the MQTT client executes the cancellation of the message merging and restores the default method of sending messages one by one.
[0075] In one embodiment of the present invention, after the MQTT proxy completes parsing of the merged message, it can generate a response message for parsing the target data result and feed the response message back to the MQTT client. If the MQTT client confirms that the response is normal, subsequent communications can continue.
[0076] When the response message received by the MQTT client is an abnormal response, the maintenance personnel can be notified to intervene. The fault is checked as soon as possible and communication is restored.
[0077] In one embodiment of the present invention, the MQTT agent can perform the parsing, verification and distribution operations of the merged message after receiving the merged message. The destination address and priority of the merged message are determined, and then according to the destination address and priority of the merged message, the MQTT agent can forward the merged message to the receiver corresponding to the destination address in order from high to low priority, wherein the receiver can be another device, server or application. In addition, the receiver can further process or display the received merged message as needed.
[0078] In an embodiment of the present invention, by obtaining device geographic information and counting the messages sent by the MQTT client during the communication between the MQTT proxy and the MQTT client, the number of messages received per unit time is obtained; then, based on the device geographic information and the number of messages received per unit time, it is determined whether to trigger the message merge sending mode; when it is determined that the message merge sending mode is triggered, a target control instruction for turning on the message merge mode can be generated; then, the target control instruction is sent to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message; the merged message sent by the MQTT client is received, thereby achieving the goal of optimizing the sending of high-frequency messages and reducing network load and MQTTBroker processing pressure.
[0079] Reference Figure 2 , shows a flowchart of another message merging method provided by an embodiment of the present invention, which is applied to an MQTT client and may specifically include the following steps:
[0080] Step S201, during the communication between the MQTT proxy and the MQTT client, sending device geographic information and transmission messages to the MQTT proxy;
[0081] The device geographic information may include but is not limited to obtaining the device's latitude and longitude, speed, direction, etc. The device geographic information in the embodiment of the present invention may be real-time geographic data.
[0082] In actual applications, the MQTT proxy is connected to the MQTT client, and two-way communication can be performed between the MQTT proxy and the MQTT client, that is, the MQTT proxy sends data to the MQTT client, and / or the MQTT client sends messages to the MQTT proxy.
[0083] During the communication between the MQTT agent and the MQTT client, the MQTT client can send real-time device geographic information to the MQTT agent. Then, after the MQTT agent receives the geographic information, it can store the device geographic information.
[0084] During the communication between the MQTT agent and the MQTT client, the MQTT client can also send transmission messages to the MQTT agent, and the MQTT agent receives the transmission messages. After the MQTT agent and the MQTT client communicate for a period of time, the MQTT agent can calculate the number of messages received per unit time during this period, and then the MQTT agent can determine whether to trigger the message merging mode based on the number of messages received per unit time and the pre-stored device geographic information. In the triggered message merging mode, the MQTT agent can generate a target control instruction for turning on the message merging mode, and send the target control instruction to the MQTT client for execution.
[0085] Step S202, receiving a target control instruction for enabling a message merging mode sent by the MQTT proxy, where the target control instruction is generated when the MQTT proxy determines to trigger the message merging sending mode based on device geographic information and the number of messages received per unit time, where the number of messages received per unit time is determined by counting messages sent by the MQTT client;
[0086] After receiving the target control instruction sent by the MQTT agent, the MQTT client turns on the message merging mode in the MQTT client. The message merging mode can merge the messages to be sent to reduce the amount of data transmission and reduce the data processing pressure of MQTT.
[0087] Step S203, merging multiple messages to be sent based on the target control instruction to obtain a merged message;
[0088] After the MQTT client receives the target control instruction, the MQTT client enters the message merging and sending mode. In the message merging and sending mode, multiple messages can be merged to obtain a merged message.
[0089] In one embodiment of the present invention, the message types of a plurality of messages to be sent are determined; when the message types are the same, the plurality of messages to be sent are merged based on a target control instruction.
[0090] For example, message body B1 and message body B2 are two messages reporting the same message type but with different contents. Since B1 and B2 are sent too frequently, a merge strategy can be used to merge and encrypt B1 and B2 in the JSON structure {B1, B2} using AES256. The strategy is that all B messages sent frequently within 10 seconds are sent in a merged manner.
[0091] In an embodiment of the present invention, multiple messages to be sent are merged based on the target control instruction to obtain a merged message, including: based on the target control instruction, the multiple messages to be sent are generated into a merged message according to a preset merged message format.
[0092] The preset merged message format can be set according to the actual scenario, and there is no excessive restriction on this in the embodiment of the present invention. For example, the preset merged message format can be: merged message type + message ciphertext list, and the format of the message ciphertext list is "forwarding direction + encryption method + ciphertext".
[0093] In one embodiment of the present invention, the MQTT client can use a preset compression algorithm to compress the target data to obtain compressed data; then encrypt the compressed data according to a preset encryption algorithm to obtain encrypted data; and send the encrypted data to the MQTT agent.
[0094] In actual applications, the MQTT client can be pre-set with compression algorithms and encryption algorithms, and can select a matching compression algorithm based on the data type of the merged message to be sent, the compression target (such as speed, compression ratio, and acceptable degree of quality loss), and the application scenario; and can select a suitable encryption algorithm for encryption based on the sensitivity, application scenario, performance requirements, and security requirements of the data to be transmitted to ensure data transmission security.
[0095] The preset compression algorithm may include a lossless compression algorithm and a lossy compression algorithm.
[0096] The preset encryption algorithm can be a symmetric encryption algorithm, an asymmetric encryption algorithm, a hash algorithm, or a block encryption algorithm.
[0097] Symmetric encryption algorithms may include DES (Data Encryption Standard), 3DES (Triple DES), and AES (Advanced Encryption Standard).
[0098] Asymmetric encryption algorithms: including RSA (Rivest-Shamir-Adleman) and ECC (Elliptic Curve Cryptography).
[0099] Hash algorithms may include: MD5 (Message Digest Algorithm 5), SHA (Secure Hash Algorithm), stream encryption algorithm, and RC4.
[0100] The block encryption algorithm may include AES (Advanced Encryption Standard).
[0101] Step S204, sending the merged message to the MQTT proxy.
[0102] In an embodiment of the present invention, during the communication between the MQTT proxy and the MQTT client, device geographic information and transmission messages are sent to the MQTT proxy; the MQTT proxy receives a target control instruction for starting the message merging mode, and the target control instruction is generated when the MQTT proxy determines to trigger the message merging sending mode based on the device geographic information and the number of messages received per unit time; based on the target control instruction, multiple messages to be sent are merged to obtain a merged message, and the merged message is sent to the MQTT proxy, thereby optimizing high-frequency message sending and reducing network load and MQTT proxy processing pressure.
[0103] Reference Figure 3 The figure shows a schematic diagram of a message merging process in an embodiment of the present invention, which involves a data interaction process between an MQTT proxy and an MQTT client. Specifically, the interaction process may include the following steps:
[0104] Step S301, after the MQTT client is started, a connection can be established with the MQTT proxy, and the MQTT client can publish device information to the MQTT proxy.
[0105] The device information may include the device geographic location. The MQTT client may periodically publish the device information to the MQTT proxy to ensure that the MQTT proxy stores the latest device geographic location of the MQTT client.
[0106] Step S302: The MQTT proxy saves the geographic location of the device.
[0107] Step S303, the MQTT client sends a message to the MQTT proxy according to the instruction;
[0108] When the user performs a control operation on the client, a corresponding message can be generated based on the user's operation instruction, and the generated message can be sent to the MQTT agent.
[0109] Step S304, the MQTT agent monitors the messages in real time and determines the frequency rate per unit time (ie, the number of messages received per unit time).
[0110] During the communication process between the MQTT proxy and the MQTT client, the MQTT proxy can monitor the messages from the MQTT client in real time, and specifically, can record the message receiving time of each message and the number of messages received within a period of time. Then, the message statistics based on unit time = number of messages received / statistical time, where the statistical time can be based on the time difference between the first message receiving time corresponding to the first received message and the second message receiving time corresponding to the last received message after the statistics start.
[0111] Step S305, the MQTT proxy calculates the number of frequently sending devices in the area and prioritizes them.
[0112] The MQTT agent can manage MQTT clients by region (determine the region of each device based on the device's geographic information) and determine the number of frequently sending devices in each region. The MQTT agent receives messages sent by frequently sending devices if the number of messages received per unit time is greater than the preset number of messages received.
[0113] In addition, multiple devices in the area can be sorted from high to low according to the number of received messages. The higher the ranking, the greater the corresponding data processing pressure.
[0114] Step S306, the MQTT proxy determines whether the number of devices that frequently send devices in the region time is too large;
[0115] The MQTT proxy can determine whether the number of frequently sending devices in a certain area is greater than a preset device number threshold. When the number of devices is greater than the preset device number threshold, step S307 is executed; when the number of devices is less than or equal to the preset device number threshold, step S309 is executed.
[0116] Step S307: When it is determined that there is too much device data, the MQTT client can start the message merging sending mode.
[0117] When the MQTT agent detects that the current number of devices is greater than the preset device number threshold, it can generate a control instruction and send it to the MQTT client. Then the MQTT client can execute the message merging sending mode according to the control instruction.
[0118] Step S308, the MQTT client changes the message sending mode to merged sending, the format is: merged message type + message cipher text list, the format of the message cipher text list is "forwarding direction + encryption method + cipher text". The MQTT client can publish the processed message.
[0119] After the MQTT client turns on the message merging sending mode, when the MQTT client subsequently sends messages to the MQTT proxy, if the messages to be sent meet the message merging conditions, the messages can be merged first and then sent to the MQTT proxy.
[0120] Step S309, the MQTT proxy determines whether the message is a merged message. After determining that the message is a merged message, the MQTT proxy can parse it according to the merged message format and return a message indicating successful parsing to the MQTT client.
[0121] After receiving the message sent by the MQTT client, the MQTT proxy can determine whether the message is a merged message. For example, the MQTT proxy can read the target field from a specific field in the packet header corresponding to the message, and determine whether the message is a merged message based on the target field. When the message is determined to be a merged message, the data can be parsed according to the merged message format, and after successful parsing, a successful parsing message is returned to the MQTT client.
[0122] When the MQTT agent determines that the received message is not a merged message, it parses and verifies the message according to the parsing method corresponding to the message.
[0123] Step S310: When it is determined that the device data is less, the MQTT client can turn off the message merging sending mode.
[0124] When the MQTT agent detects that the current number of devices is less than or equal to a preset device number threshold, the MQTT agent can generate a second control instruction, and then the second control instruction can be sent to the MQTT client to control the MQTT client to cancel the current message merging mode.
[0125] The MQTT system involved in the method of the embodiment of the present invention may include a module for data collection, a module for real-time analysis, a module for message merging, an MQTT agent, and related hardware devices. The module for data collection is responsible for collecting the geographic location and time data of the device in real time, and can be implemented by hardware devices such as a GPS positioning module and a network positioning module. The module for real-time analysis and the module for message merging can be software programs running on a server, responsible for analyzing and processing the collected data. The MQTT agent is responsible for receiving the merged message, parsing, processing, and distributing it.
[0126] Based on the interaction between the modules of the above system, the message merging process in the embodiment of the present invention can be divided into the following stages:
[0127] Data collection stage: The module used for data collection obtains the device's latitude, longitude, speed, direction and other geographic location information in real time through the GPS positioning module or the network positioning module, and records the timestamp of the device sending the message. These data can be sent to the module for real-time analysis through a wireless transmission module (such as Wi-Fi, Bluetooth, 4G / 5G, etc.).
[0128] Data preprocessing stage: After receiving the data, the module used for real-time analysis first preprocesses the data. Preprocessing can include data cleaning, format conversion, outlier processing, etc. Specifically, in the data cleaning stage, the module will remove duplicate, erroneous or invalid data; in the format conversion stage, the module will convert the data into a unified format for subsequent analysis; in the outlier processing stage, the module will identify and process abnormal data to ensure the accuracy and reliability of the data.
[0129] Real-time analysis and message merging strategy formulation: The module used for real-time analysis can analyze based on the device's geographic location and time information. The device's movement state is determined by calculating parameters such as the device's movement speed, acceleration, and direction change. When the device is relatively stationary or moving at a low speed, the real-time analysis module will determine whether there is a need for message merging and formulate a corresponding message merging strategy. The strategy can include the merged time window, geographic range, message type, etc., and can be dynamically adjusted according to actual needs.
[0130] Message merging and optimization: The module for message merging merges messages that meet the merging conditions according to the strategy formulated by the module for real-time analysis. During the merging process, the message content can be compressed to remove redundant information and further reduce the network load. At the same time, in order to ensure the security of the message, the merged message will also be encrypted.
[0131] Message sending and processing: The merged, compressed, and encrypted messages are sent to the MQTT agent through the MQTT protocol. After receiving the message, the MQTT agent performs parsing, verification, and distribution operations. According to the destination address and priority of the message, the MQTT agent forwards the message to the corresponding receiver, such as other devices, servers, or applications. The receiver can further process or display the message as needed.
[0132] Based on the above description of the embodiments of the present invention, the embodiments of the present invention have the following advantages:
[0133] (1) Reduce network load and improve network performance. By analyzing the device's geographic location and time data in real time (such as the number of messages received per unit time), the system can determine the need for message merging and merge messages that originally needed to be sent separately into fewer messages for sending. This approach significantly reduces the number of network requests and the amount of data transmitted, thereby effectively reducing the network load. The reduction in network load means that network resources are used more efficiently, network congestion is alleviated, and the transmission efficiency and performance of the network are improved.
[0134] (2) Reduce the processing pressure of the MQTT agent and improve the system response speed. When processing a large number of messages, the MQTT agent often faces problems such as increased processing pressure and response delays. This patent proposal reduces the number of messages that the agent needs to process by merging messages, thereby significantly reducing its processing pressure. This means that the agent can respond and process messages more quickly, improving the system's response speed and processing capabilities. This improvement is particularly critical for application scenarios with high real-time requirements, such as smart transportation and industrial automation.
[0135] (3) Improve data transmission efficiency and system performance By merging messages, not only the number of network requests and the amount of data transmitted are reduced, but also the redundancy and repetition in the data transmission process are reduced. This improves the efficiency of data transmission, allowing data to be transmitted from the sender to the receiver in a shorter time. At the same time, since the number of merged messages is reduced, the amount of data that the system needs to process is also reduced accordingly, further improving the overall performance of the system.
[0136] (4) Improve system flexibility and adaptability The message merging strategy in this patent proposal is based on real-time analysis of device geographic location and time data, so it has high flexibility and adaptability. The system can dynamically adjust the merged time window, geographic range and other parameters based on factors such as the device's movement speed, location changes, and time distribution to adapt to changes in demand in different scenarios. This flexibility enables the system to better cope with various complex situations and improves its reliability and stability in practical applications.
[0137] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0138] Reference Figure 4 , shows a schematic diagram of the structure of a message merging device provided by an embodiment of the present invention, which is applied to an MQTT proxy end and may specifically include the following modules:
[0139] The data acquisition module 401 is used to acquire device geographic information, count messages sent by the MQTT client, and obtain the number of messages received per unit time during the communication between the MQTT proxy and the MQTT client;
[0140] A triggering judgment module 402, configured to judge whether to trigger a message merging and sending mode based on the device geographic information and the number of messages received within the unit time;
[0141] The target control instruction generating module 403 is used to generate a target control instruction for starting the message merging mode when it is determined that the message merging sending mode is triggered;
[0142] The target control instruction sending module 404 is used to send the target control instruction to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message;
[0143] The merge message receiving module 405 is used to receive the merge message sent by the MQTT client.
[0144] In an embodiment of the present invention, the trigger determination module 402 may include:
[0145] A device area division submodule, used to determine the number of message receptions of each device in a preset area based on the device geographic information;
[0146] A device determination submodule, configured to determine that the target device is a device that frequently sends messages within the preset area when the number of messages received by the target device within a unit time is greater than a preset number of messages received;
[0147] A device quantity statistics submodule, used to count the number of devices that frequently send messages;
[0148] A quantity determination submodule is used to determine whether the number of devices is greater than a preset device quantity threshold;
[0149] The trigger submodule is used to determine a trigger message merge sending mode when the number of devices is greater than a preset device number threshold.
[0150] In one embodiment of the present invention, the data acquisition module 401 includes:
[0151] A message receiving module is used to obtain the message sending time of the MQTT client and count the total number of messages received;
[0152] The receiving number determination module is used to calculate the time interval of the message sending time and the number of message receptions per unit time of the total number of message receptions.
[0153] In one embodiment of the present invention, the device further comprises:
[0154] A merge message judgment module is used to judge whether the message sent by the MQTT client is a merge message;
[0155] The merged message parsing module is used to parse the merged message using a preset merged message format when determining that the message sent by the MQTT client is a merged message.
[0156] Reference Figure 5 , shows a schematic diagram of the structure of another message merging device provided by an embodiment of the present invention, which is applied to an MQTT client and may specifically include the following modules:
[0157] The data sending module 501 is used to send device geographic information and transmission messages to the MQTT proxy during the communication between the MQTT proxy and the MQTT client;
[0158] A target control instruction receiving module 502 is used to receive a target control instruction sent by the MQTT proxy end for turning on the message merging mode, wherein the target control instruction is generated by the MQTT proxy end when the message merging sending mode is triggered based on the device geographic information and the number of messages received per unit time, and the number of messages received per unit time is determined by counting the messages sent by the MQTT client;
[0159] The message merging module 503 is used to merge multiple messages to be sent based on the target control instruction to obtain a merged message.
[0160] The merged message sending module 504 is used to send the merged message to the MQTT proxy end.
[0161] In one embodiment of the present invention, the device further comprises:
[0162] A message type determination module, used to determine the message types of multiple messages to be sent;
[0163] A merging execution module is used to execute the merging of multiple messages to be sent based on the target control instruction when the message types are the same.
[0164] In an embodiment of the present invention, the message merging module 503 is specifically used to: generate a merged message according to a preset merged message format from multiple messages to be sent based on the target control instruction.
[0165] In one embodiment of the present invention, the device further comprises:
[0166] A compression processing module, used to compress the target data using a preset compression algorithm to obtain compressed data;
[0167] An encryption processing module, used to encrypt the compressed data according to a preset encryption algorithm to obtain encrypted data;
[0168] The encrypted data sending module is used to send the encrypted data to the MQTT agent.
[0169] An embodiment of the present invention provides an electronic device, including a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the message merging method as described above when executed by the processor.
[0170] An embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the message merging method described above is implemented.
[0171] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0172] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0173] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0174] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0175] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0176] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0177] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0178] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0179] The above is a detailed introduction to the message merging method and device, electronic device, and storage medium provided. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A message merging method, characterized in that: Applied to the MQTT agent, the method includes: During the communication between the MQTT proxy and the MQTT client, the device geographic information is obtained, the messages sent by the MQTT client are counted, and the number of messages received per unit time is obtained; Determining whether to trigger the message merge sending mode based on the device geographic information and the number of messages received within the unit time; When it is determined that the message merging sending mode is triggered, generating a target control instruction for starting the message merging mode; Sending the target control instruction to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message; Receive the merged message sent by the MQTT client.
2. The method according to claim 1, characterized in that: The determining whether to trigger the message merge sending mode based on the device geographic information and the number of messages received within the unit time includes: Determine the number of messages received by each device in a preset area within a unit time based on the device geographic information; When the number of messages received by the target device within a unit time is greater than a preset number of messages received, determining that the target device is a device that frequently sends messages within the preset area; Counting the number of devices that frequently send messages; Determine whether the number of devices is greater than a preset device number threshold; When the number of devices is greater than the preset device number threshold, a trigger message merge sending mode is determined.
3. The method according to claim 1, characterized in that The counting of messages sent by the MQTT client to obtain the number of messages received per unit time includes: Obtain the message sending time of the MQTT client and count the total number of messages received; The time interval of the message sending time and the number of messages received per unit time of the total number of messages received are calculated.
4. The method according to claim 1, characterized in that: Also includes: Determine whether the message sent by the MQTT client is a merged message; When it is determined that the message sent by the MQTT client is a merged message, the merged message is parsed using a preset merged message format.
5. A message merging method, characterized in that: Applied to the MQTT client, the method includes: During the communication between the MQTT proxy and the MQTT client, sending device geographic information and transmission messages to the MQTT proxy; Receiving a target control instruction sent by the MQTT proxy for turning on a message merging mode, the target control instruction being generated when the MQTT proxy determines to trigger the message merging sending mode based on the device geographic information and the number of messages received per unit time, the number of messages received per unit time being determined by counting messages sent by the MQTT client; Merging multiple messages to be sent based on the target control instruction to obtain a merged message; The merged message is sent to the MQTT proxy.
6. The method according to claim 5, characterized in that Also includes: Determine the message types of multiple messages to be sent; When the message types are the same, the step of merging multiple messages to be sent based on the target control instruction is executed.
7. The method according to claim 5, characterized in that The step of merging a plurality of messages to be sent based on the target control instruction to obtain a merged message includes: Based on the target control instruction, a plurality of messages to be sent are used to generate a merged message in a preset merged message format.
8. The method according to claim 5, characterized in that Also includes: Using a preset compression algorithm to compress the target data to obtain compressed data; Encrypting the compressed data according to a preset encryption algorithm to obtain encrypted data; The encrypted data is sent to the MQTT agent.
9. A message merging device, characterized in that: Applied to the MQTT proxy end, the device includes: A data acquisition module, used to acquire device geographic information, count messages sent by the MQTT client, and obtain the number of messages received per unit time during the communication between the MQTT proxy and the MQTT client; A trigger judgment module, used to judge whether to trigger the message merge sending mode based on the device geographic information and the number of message receptions within the unit time; A target control instruction generating module, used for generating a target control instruction for starting the message merging mode when it is determined that the message merging sending mode is triggered; A target control instruction sending module, used for sending the target control instruction to the MQTT client, so that the MQTT client merges multiple messages to be sent based on the target control instruction to obtain a merged message; The merged message receiving module is used to receive the merged message sent by the MQTT client.
10. A message merging device, characterized in that: Applied to the MQTT client, the device comprises: A data sending module, used to send device geographic information and transmission messages to the MQTT proxy during the communication between the MQTT proxy and the MQTT client; A target control instruction receiving module, used to receive a target control instruction sent by the MQTT agent to enable a message merging mode, wherein the target control instruction is generated by the MQTT agent when the message merging sending mode is triggered based on the device geographic information and the number of messages received per unit time, wherein the number of messages received per unit time is determined by counting the messages sent by the MQTT client; A message merging module, used to merge multiple messages to be sent based on the target control instruction to obtain a merged message; The merged message sending module is used to send the merged message to the MQTT agent.
11. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the message merging method according to any one of claims 1 to 8 is implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the message merging method according to any one of claims 1 to 8 is implemented.
