Message theme registration method and message sending method

By managing the mapping between MQTT topics and identifiers through a topic registration server, and generating unique identifiers to replace message topics for communication, the problem of high data bandwidth in MQTT protocol transmission is solved, and the data traffic cost of devices is reduced.

CN121283992APending Publication Date: 2026-01-06ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511366240.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-23
Publication Date
2026-01-06

AI Technical Summary

Technical Problem

In existing technologies, the bandwidth of MQTT topic data transmission in MQTT protocol is relatively high, resulting in high data traffic costs for devices.

Method used

The mapping between message topics and identification codes is managed by a topic registration server, generating unique identification codes to replace message topics for communication, thereby reducing network transmission bandwidth.

Benefits of technology

It effectively reduces the data bandwidth in MQTT protocol transmission and reduces data traffic costs for devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121283992A_ABST
    Figure CN121283992A_ABST
Patent Text Reader

Abstract

The invention discloses a message theme registration method and device, a storage medium and an electronic device, and the method comprises the steps: determining whether a second message theme corresponding to a theme registration request is registered or not under the condition that the theme registration request sent by communication equipment is received; when it is determined that the second message theme is not registered, a first identification code corresponding to the second message theme is randomly generated, and the first identification code is used for uniquely identifying the second message theme; the corresponding relation between the second message theme and the first identification code is stored, and the first identification code is sent to the communication equipment; by adopting the above scheme, the problem of how to reduce the data bandwidth of the MQTT theme in the MQTT protocol transmission so as to reduce the data traffic expense of the equipment in the related technology is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communications, and more specifically, to a method for registering message topics and a method for sending messages. Background Technology

[0002] In the IoT ecosystem, the MQTT protocol, due to its conciseness and low consumption of device performance and resources, is particularly suitable for low-code and low-bandwidth scenarios. Many low-end devices access platforms using cellular communication (such as NB-IoT and 4G), making them sensitive to data traffic costs. In practical scenarios, MQTT topics can be as long as several hundred bytes. Every message sent or received by a device needs to carry an MQTT topic. This leads to a scenario where the actual business data transmitted by the device only occupies a few dozen bytes, but an MQTT topic much larger than the business data needs to be carried.

[0003] There is still no effective solution to the problem of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of devices. Summary of the Invention

[0004] This application provides a method for registering a message topic and a method for sending a message, in order to at least solve the problem in the related art of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of the device.

[0005] According to one embodiment of this application, a method for registering a message topic is provided, applied to a topic registration server, comprising: upon receiving a topic registration request sent by a communication device, determining whether a second message topic corresponding to the topic registration request has been registered; if it is determined that the second message topic has not been registered, randomly generating a first identification code corresponding to the second message topic, wherein the first identification code is used to uniquely identify the second message topic; saving the correspondence between the second message topic and the first identification code, and sending the first identification code to the communication device.

[0006] In an exemplary embodiment, after saving the correspondence between the second message topic and the first identification code and sending the first identification code to the communication device, the method further includes: upon receiving an identification code conversion request sent by a message middleware, obtaining a second identification code carried in the identification code conversion request; responding to the identification code conversion request, matching the first message topic corresponding to the second identification code in mapping data, wherein the mapping data is used to indicate a one-to-one correspondence between multiple identification codes and multiple message topics; sending the first message topic to the message middleware to instruct the message middleware to distribute a first message to a first subscription device that has subscribed to the first message topic, wherein the first message corresponds to the second identification code.

[0007] In an exemplary embodiment, after determining whether the second message topic corresponding to the topic registration request has been registered, the method further includes: if it is determined that the second message topic has been registered, querying the mapping data stored in the topic registration server for the first identification code corresponding to the second message topic, wherein the mapping data is used to indicate a one-to-one correspondence between multiple identification codes and multiple message topics; and sending the first identification code to the communication device.

[0008] In one exemplary embodiment, randomly generating a first identifier corresponding to the second message topic includes: determining the number of identifiers among a plurality of identifiers registered by the topic registration server, and determining a first length of the largest identifier among the plurality of identifiers; obtaining a quantity threshold corresponding to the first length, and determining whether the number of identifiers is greater than the quantity threshold; if the number of identifiers is less than the quantity threshold, randomly generating the first identifier according to the first length; if the number of identifiers is greater than or equal to the quantity threshold, determining a second length according to the first length, and randomly generating the first identifier according to the second length, wherein the second length is greater than the first length.

[0009] According to another embodiment of this application, a message sending method is provided, applied to a communication device, comprising: when it is determined that the communication device has a message to be sent, determining whether the communication device stores a first identification code of a second message topic corresponding to the message to be sent, wherein the first identification code is used to uniquely identify the second message topic; when it is determined that the communication device does not store the first identification code, sending a topic registration request to a topic registration server, wherein the topic registration request is used to request registration of the first identification code corresponding to the second message topic; receiving the first identification code sent by the topic registration server, generating a second message according to the first identification code and the message to be sent, and sending the second message to a message middleware to instruct the message middleware to distribute the second message to second subscribing devices that have subscribed to the second message topic.

[0010] In an exemplary embodiment, after determining whether the communication device stores a first identification code for the second message subject corresponding to the message to be sent, the method further includes: if it is determined that the communication device stores the first identification code, generating the second message based on the first identification code and the message to be sent; and sending the second message to the message middleware.

[0011] According to another embodiment of the present application, a message topic registration device is also provided, comprising: a first determining module, configured to determine whether a second message topic corresponding to the topic registration request has been registered upon receiving a topic registration request sent by a communication device; a generating module, configured to randomly generate a first identification code corresponding to the second message topic if it is determined that the second message topic has not been registered, wherein the first identification code is used to uniquely identify the second message topic; and a first sending module, configured to save the correspondence between the second message topic and the first identification code, and send the first identification code to the communication device.

[0012] According to another embodiment of the present application, a message sending apparatus is also provided, comprising: a second determining module, configured to determine whether the communication device stores a first identification code of a second message topic corresponding to the message to be sent when it is determined that the communication device has a message to be sent, wherein the first identification code is used to uniquely identify the second message topic; a second sending module, configured to send a topic registration request to a topic registration server when it is determined that the communication device does not store the first identification code, wherein the topic registration request is used to request registration of the first identification code corresponding to the second message topic; and a third sending module, configured to receive the first identification code sent by the topic registration server, generate a second message according to the first identification code and the message to be sent, and send the second message to a message middleware to instruct the message middleware to distribute the second message to second subscribing devices that have subscribed to the second message topic.

[0013] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer program, and the computer program is configured to execute the above-described message topic registration method or the above-described message sending method when it runs.

[0014] According to another aspect of the embodiments of this application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above-described message topic registration method or the above-described message sending method through the computer program.

[0015] In this embodiment, when the topic registration server receives a topic registration request from a communication device, it determines whether the second message topic corresponding to the topic registration request has been registered. If it is determined that the second message topic has not been registered, a first identification code corresponding to the second message topic is randomly generated, the correspondence between the second message topic and the first identification code is saved, and the first identification code is sent to the communication device. By adopting the above scheme, the topic registration server manages the relationship between message topics and identification codes, so that any device can communicate using identification codes instead of message topics, effectively reducing network transmission bandwidth. This solves the problem in related technologies of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of devices. Attached Figure Description

[0016] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0017] Figure 1This is a hardware structure block diagram of a topic registration server, which is an optional message topic registration method according to an embodiment of this application.

[0018] Figure 2 This is a flowchart of an optional message topic registration method according to an embodiment of this application;

[0019] Figure 3 This is a flowchart of an optional message sending method according to an embodiment of this application;

[0020] Figure 4 This is a flowchart illustrating an optional MQTT topic compression method according to an embodiment of this application;

[0021] Figure 5 This is a flowchart of an optional message subscription / publishing method according to an embodiment of this application;

[0022] Figure 6 This is a structural block diagram of an optional message topic registration device according to an embodiment of this application;

[0023] Figure 7 This is a structural block diagram of an optional message sending device according to an embodiment of this application. Detailed Implementation

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

[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0026] The method embodiments provided in this application can be executed in a topic registration server or a similar computing system. Taking running on a topic registration server as an example, Figure 1 This is a hardware structure block diagram of a topic registration server, representing a method for registering message topics according to an embodiment of this application. For example... Figure 1 As shown, a topic registry server may include one or more ( Figure 1 Only one is shown in the image. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. In one exemplary embodiment, the aforementioned subject registration server may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the topic registration server described above. For example, the topic registration server may also include... Figure 1 The more or fewer components shown, or having the same Figure 1 Equivalent functions or ratios shown Figure 1 The functions shown have more different configurations.

[0027] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the message topic registration method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thus implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage systems, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the secure text via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0028] The transmission system 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the topic registration server. In one example, the transmission system 106 includes a network interface controller (NIC), which can connect to other network devices via a base station to communicate with the Internet.

[0029] This embodiment provides a method for registering message topics, applied to the aforementioned topic registration server. Figure 2 This is a flowchart of an optional message topic registration method according to an embodiment of this application, the process including the following steps:

[0030] Step S202: Upon receiving a topic registration request sent by a communication device, determine whether the second message topic corresponding to the topic registration request has been registered;

[0031] Step S204: If it is determined that the second message topic is not registered, a first identification code corresponding to the second message topic is randomly generated, wherein the first identification code is used to uniquely identify the second message topic;

[0032] Step S206: Save the correspondence between the second message topic and the first identification code, and send the first identification code to the communication device.

[0033] Through the above steps, when the topic registration server receives a topic registration request from a communication device, it determines whether the second message topic corresponding to the topic registration request has already been registered. If it is determined that the second message topic has not been registered, a first identification code corresponding to the second message topic is randomly generated, the correspondence between the second message topic and the first identification code is saved, and the first identification code is sent to the communication device. By adopting the above scheme, the topic registration server manages the relationship between message topics and identification codes, enabling any device to communicate using identification codes instead of message topics, effectively reducing network transmission bandwidth. This solves the problem in related technologies of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of devices.

[0034] Optionally, after saving the correspondence between the second message topic and the first identification code and sending the first identification code to the communication device, the method further includes: upon receiving an identification code conversion request sent by the message middleware, obtaining the second identification code carried in the identification code conversion request; responding to the identification code conversion request, matching the first message topic corresponding to the second identification code in the mapping data, wherein the mapping data is used to indicate a one-to-one correspondence between multiple identification codes and multiple message topics; sending the first message topic to the message middleware to instruct the message middleware to distribute the first message to a first subscription device that has subscribed to the first message topic, wherein the first message corresponds to the second identification code.

[0035] In this embodiment, the MQTT topic registration server stores the correspondence between the second message topic and the first identifier and sends the first identifier to the communication device. Furthermore, the server is also responsible for processing identifier conversion requests. Specifically, when the message middleware sends an identifier conversion request, the server immediately obtains the carried second identifier and then quickly matches it with the first message topic corresponding to the second identifier in the pre-stored mapping data. The mapping data is essentially a database table that records the correspondence between all assigned identifiers and the original message topics. After completing the matching, the server feeds back the first message topic to the message middleware, ensuring that the message middleware can accurately distribute the first message to all first-subscribed devices that have subscribed to the first message topic based on this topic.

[0036] It should be noted that the MQTT topic registry server is a service entity specifically used to manage and distribute MQTT topic identifiers. It maintains a mapping table between topics and identifiers. When a communication device requests a topic identifier, the server is responsible for generating a new identifier, updating the mapping table, and returning the identifier to the requesting device.

[0037] It should be noted that the first and second identifiers are codes representing MQTT topics, used to replace the long string format of the second and first message topics in network transmission to reduce data volume and bandwidth consumption.

[0038] In summary, this embodiment aims to achieve efficient compression and conversion of MQTT topics through a topic registration server, optimize network data transmission between communication devices, reduce traffic costs, and improve the overall system's communication efficiency and reliability.

[0039] Optionally, after determining whether the second message topic corresponding to the topic registration request has been registered, the method further includes: if it is determined that the second message topic has been registered, querying the mapping data stored in the topic registration server for the first identification code corresponding to the second message topic, wherein the mapping data is used to indicate a one-to-one correspondence between multiple identification codes and multiple message topics; and sending the first identification code to the communication device.

[0040] In this embodiment, after receiving a topic registration request and determining that the corresponding second message topic has already been registered, the topic registration server immediately performs a search operation in its maintained mapping data to retrieve a first identifier that matches the second message topic. The mapping data is essentially a detailed register, where each line records a unique identifier and its corresponding complete message topic, ensuring a clear and unique association between the two. After successfully locating the first identifier, the server transmits it to the communication device that initiated the request, thereby enabling rapid referencing of registered topics and reducing the data load in subsequent message transmissions.

[0041] This embodiment utilizes the mapping data function of the topic registration server. Once it is confirmed that the message topic has been registered, the corresponding identification code can be quickly found, thereby enabling more compact message exchange between communication devices, reducing data transmission bandwidth, and improving the efficiency of IoT communication.

[0042] Further, randomly generating a first identifier corresponding to the second message topic includes: determining the number of identifiers among multiple identifiers registered by the topic registration server, and determining a first length of the largest identifier among the multiple identifiers; obtaining a quantity threshold corresponding to the first length, and determining whether the number of identifiers is greater than the quantity threshold; if the number of identifiers is less than the quantity threshold, randomly generating the first identifier according to the first length; if the number of identifiers is greater than or equal to the quantity threshold, determining a second length according to the first length, and randomly generating the first identifier according to the second length, wherein the second length is greater than the first length.

[0043] This embodiment focuses on the dynamic strategy for generating identification codes by the topic registration server. The server first counts the total number of registered identification codes and the current maximum length of each code. Then, it assesses whether the code length needs to be increased based on a preset threshold. If the number of registered identification codes does not exceed this threshold, the server generates a new identification code based on the current maximum length; otherwise, if the threshold is exceeded, the code length needs to be increased incrementally to ensure the uniqueness of the newly generated identification codes. This threshold setting is to prevent the exhaustion of identification codes within the same length, thereby ensuring the long-term stable operation of the system.

[0044] It should be noted that the quantity threshold is a critical value used to determine whether the identification code length needs to be increased. The server calculates the maximum number of identification codes it can accommodate based on the current identification code length. When the number of registrations approaches this threshold, the identification code length will be automatically increased to avoid duplication.

[0045] By implementing this strategy, the topic registration server maintains both the compactness and sufficient supply of identifiers, balancing the needs of topic compression with system scalability. This method effectively overcomes the problem of identifier space exhaustion caused by an increase in registered topics, providing necessary technical support for large-scale IoT deployments.

[0046] In another embodiment of this application, a message sending method is provided, applied to a communication device. Figure 3 This is a flowchart of an optional message sending method according to an embodiment of this application, the process including the following steps:

[0047] Step S302: If it is determined that there is a message to be sent on the communication device, determine whether the communication device stores a first identification code of the second message topic corresponding to the message to be sent, wherein the first identification code is used to uniquely identify the second message topic;

[0048] Step S304: If it is determined that the communication device does not store the first identification code, a topic registration request is sent to the topic registration server, wherein the topic registration request is used to request the registration of the first identification code corresponding to the second message topic;

[0049] Step S306: Receive the first identification code sent by the topic registration server, generate a second message based on the first identification code and the message to be sent, and send the second message to the message middleware to instruct the message middleware to distribute the second message to the second subscription devices that have subscribed to the second message topic.

[0050] Through the above steps, when it is determined that there is a message to be sent in the communication device, it is first determined whether the communication device stores the first identification code of the second message topic corresponding to the message to be sent. If it is not stored, a topic registration request is sent to the topic registration server to request the registration of the first identification code corresponding to the second message topic; the first identification code returned by the topic registration server is received, a second message is generated according to the first identification code and the message to be sent, and the second message is sent to the message middleware, instructing the message middleware to distribute the second message to the second subscribing devices that have subscribed to the second message topic; by adopting the above scheme, the problem of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of the device, is solved in related technologies.

[0051] In an exemplary embodiment, after determining whether the communication device stores a first identification code for the second message subject corresponding to the message to be sent, the method further includes: if it is determined that the communication device stores the first identification code, generating the second message based on the first identification code and the message to be sent; and sending the second message to the message middleware.

[0052] In this embodiment, before sending the second message, the communication device checks whether it already has a compressed identifier—a first identification code—for the second message subject corresponding to this message. If the device has this identification code in its memory, it then uses it to combine with the message to be sent to generate the second message. Subsequently, the communication device directly transmits the constructed second message to the message middleware, completing the message sending process.

[0053] The advantage of this embodiment is that the communication device can quickly construct and send the second message using the locally cached identification code, without repeatedly querying the topic registration server, which greatly improves the message generation and sending speed, while reducing unnecessary network burden during communication and maximizing the benefits of message topic compression.

[0054] In an optional embodiment, this application proposes an optional MQTT topic compression method, the process of which is as follows: Figure 4 As shown, it includes the following steps:

[0055] 1. After receiving an MQTT topic registration request (equivalent to the topic registration request mentioned above), the MQTT topic registration server (equivalent to the topic registration request mentioned above) identifies the request;

[0056] 2. Determine if the topic corresponding to the request has been registered; if so, proceed to step 3; otherwise, proceed to step 4.

[0057] 3. Read the unique identifier corresponding to the topic (equivalent to the first identifier mentioned above);

[0058] 4. Randomly generate a unique identification code;

[0059] 5. Save the relationship between the subject and the identification code;

[0060] 6. Return the identification code to the subscriber (equivalent to the aforementioned communication device).

[0061] It should be noted that the above subscriber (communication device) refers to any device that communicates based on the MQTT protocol, including sub-devices and gateway nodes.

[0062] It should be noted that the MQTT topic registration server mentioned above can generate a unique identifier for each MQTT topic, store the correspondence between MQTT topics and identifiers, and provide a request interface for retrieving the identifier corresponding to an MQTT topic.

[0063] It should be noted that subscribers can send a request to the MQTT topic registration server through some protocol (MQTT protocol, COAP protocol, HTTP protocol, etc., but not limited to these) to obtain the identification code corresponding to the MQTT topic.

[0064] It should be noted that the length of the identification code generated by the server increases from small to large. The initial length is configurable. For example, the initial length of the identification code is 2 bytes, but once the identifier of two bytes is allocated, the length of the subsequent generated identification codes will be 3 bytes, and so on.

[0065] In another embodiment of this application, a message subscription / publishing method is provided, which combines... Figure 5 The processing timing of this method will be further explained, such as... Figure 5 As shown, the specific steps include:

[0066] 1. The subscriber requests compressed MQTT topic data from the MQTT message middleware (equivalent to the message middleware mentioned above);

[0067] 2. The MQTT message middleware forwards the request to the MQTT topic registration service (equivalent to the topic registration server mentioned above);

[0068] 3. The MQTT topic registration service reads the identification code (equivalent to the first identification code mentioned above) corresponding to the MQTT topic (equivalent to the first message topic mentioned above);

[0069] 4. The MQTT topic registration service returns an identification code to the subscriber;

[0070] 5. The MQTT message middleware forwards the identification code to the subscribers;

[0071] 6. Subscribers use this identifier as the topic to initiate a topic subscription with the MQTT message middleware;

[0072] 7. The MQTT message middleware returns the subscription result;

[0073] 8. Subscribers can also use this identifier as the subject of published messages;

[0074] 9. The MQTT message middleware returns the publication result.

[0075] Using the message subscription / publishing method described above, before publishing or subscribing to an MQTT topic, the device first checks if it has a corresponding identifier for that topic locally. If it does, it directly uses the identifier as the topic for publishing or subscribing. If not, it obtains the identifier from the MQTT registry server. Therefore, when the device sends or receives MQTT messages subsequently, the topic information included is always the identifier. This effectively reduces message length, thereby reducing network transmission bandwidth and saving network traffic.

[0076] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to 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 this application, 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) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.

[0077] Figure 6 This is a structural block diagram of a message topic registration device according to an embodiment of this application; as shown below. Figure 6 As shown, it includes:

[0078] The first determining module 62 is used to determine whether the second message topic corresponding to the topic registration request has been registered when a topic registration request is received from a communication device.

[0079] The generation module 64 is used to randomly generate a first identification code corresponding to the second message topic when it is determined that the second message topic is not registered, wherein the first identification code is used to uniquely identify the second message topic;

[0080] The first sending module 66 is used to save the correspondence between the second message subject and the first identification code, and send the first identification code to the communication device.

[0081] With the above-described device, when the topic registration server receives a topic registration request from a communication device, it determines whether the second message topic corresponding to the topic registration request has already been registered. If it is determined that the second message topic has not been registered, a first identification code corresponding to the second message topic is randomly generated, the correspondence between the second message topic and the first identification code is saved, and the first identification code is sent to the communication device. By adopting the above scheme, the topic registration server manages the relationship between message topics and identification codes, enabling any device to communicate using identification codes instead of message topics, effectively reducing network transmission bandwidth. This solves the problem in related technologies of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of devices.

[0082] In an exemplary embodiment, the first sending module 66 is further configured to, upon receiving an identification code conversion request sent by the message middleware, obtain a second identification code carried in the identification code conversion request; respond to the identification code conversion request, match a first message topic corresponding to the second identification code in mapping data, wherein the mapping data is used to indicate a one-to-one correspondence between multiple identification codes and multiple message topics; and send the first message topic to the message middleware to instruct the message middleware to distribute a first message to a first subscription device that has subscribed to the first message topic, wherein the first message corresponds to the second identification code.

[0083] In an exemplary embodiment, the first determining module 62 is further configured to, upon determining that the second message topic has been registered, query the mapping data stored in the topic registration server for the first identification code corresponding to the second message topic, wherein the mapping data is used to indicate a one-to-one correspondence between multiple identification codes and multiple message topics; and send the first identification code to the communication device.

[0084] In an exemplary embodiment, the generation module 64 is further configured to: determine the number of identifiers of a plurality of identifiers registered by the topic registration server; determine a first length of the largest identifier among the plurality of identifiers; obtain a quantity threshold corresponding to the first length; and determine whether the number of identifiers is greater than the quantity threshold; if the number of identifiers is less than the quantity threshold, randomly generate the first identifier based on the first length; if the number of identifiers is greater than or equal to the quantity threshold, determine a second length based on the first length; and randomly generate the first identifier based on the second length, wherein the second length is greater than the first length.

[0085] Figure 7 This is a structural block diagram of a message sending device according to an embodiment of this application; as shown below. Figure 7 As shown, it includes:

[0086] The second determining module 72 is used to determine whether the communication device stores a first identification code of the second message topic corresponding to the message to be sent when it is determined that the communication device has a message to be sent. The first identification code is used to uniquely identify the second message topic.

[0087] The second sending module 74 is configured to send a topic registration request to the topic registration server when it is determined that the communication device does not store the first identification code, wherein the topic registration request is used to request the registration of the first identification code corresponding to the second message topic;

[0088] The third sending module 76 is used to receive the first identification code sent by the topic registration server, generate a second message based on the first identification code and the message to be sent, and send the second message to the message middleware to instruct the message middleware to distribute the second message to the second subscription device that has subscribed to the second message topic.

[0089] With the above-described apparatus, when it is determined that a message to be sent exists in the communication device, it is first determined whether the communication device stores the first identification code of the second message topic corresponding to the message to be sent. If not, a topic registration request is sent to the topic registration server to request the registration of the first identification code corresponding to the second message topic. The first identification code returned by the topic registration server is received, and a second message is generated according to the first identification code and the message to be sent. The second message is then sent to the message middleware, which instructs the message middleware to distribute the second message to the second subscribing devices that have subscribed to the second message topic. By adopting the above-described scheme, the problem of how to reduce the data bandwidth of MQTT topics in MQTT protocol transmission, thereby reducing the data traffic cost of the device, is solved in the related technology.

[0090] In an exemplary embodiment, the second determining module 72 is further configured to, when determining that the communication device stores the first identification code, generate the second message based on the first identification code and the message to be sent; and send the second message to the message middleware.

[0091] Embodiments of this application also provide a storage medium including a stored program, wherein the program executes any of the methods described above when it is run.

[0092] Optionally, in this embodiment, the storage medium may be configured to store program code for performing the following steps:

[0093] S1, upon receiving a topic registration request sent by a communication device, determine whether the second message topic corresponding to the topic registration request has been registered;

[0094] S2, if it is determined that the second message topic is not registered, a first identification code corresponding to the second message topic is randomly generated, wherein the first identification code is used to uniquely identify the second message topic;

[0095] S3, save the correspondence between the second message topic and the first identification code, and send the first identification code to the communication device.

[0096] Optionally, in this embodiment, the storage medium may also be configured to store program code for performing the following steps:

[0097] S4, if it is determined that there is a message to be sent on the communication device, determine whether the communication device stores a first identification code of the second message topic corresponding to the message to be sent, wherein the first identification code is used to uniquely identify the second message topic;

[0098] S5, if it is determined that the communication device does not store the first identification code, a topic registration request is sent to the topic registration server, wherein the topic registration request is used to request the registration of the first identification code corresponding to the second message topic;

[0099] S6, receive the first identification code sent by the topic registration server, generate a second message based on the first identification code and the message to be sent, and send the second message to the message middleware to instruct the message middleware to distribute the second message to the second subscription device that has subscribed to the second message topic.

[0100] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0101] Specific examples in this embodiment can be found in the examples described in the above embodiments and exemplary implementations, and will not be repeated here.

[0102] Embodiments of this application also provide an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above method embodiments.

[0103] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program:

[0104] S1, upon receiving a topic registration request sent by a communication device, determine whether the second message topic corresponding to the topic registration request has been registered;

[0105] S2, if it is determined that the second message topic is not registered, a first identification code corresponding to the second message topic is randomly generated, wherein the first identification code is used to uniquely identify the second message topic;

[0106] S3, save the correspondence between the second message topic and the first identification code, and send the first identification code to the communication device.

[0107] Optionally, in this embodiment, the processor may also be configured to perform the following steps via a computer program:

[0108] S4, if it is determined that there is a message to be sent on the communication device, determine whether the communication device stores a first identification code of the second message topic corresponding to the message to be sent, wherein the first identification code is used to uniquely identify the second message topic;

[0109] S5, if it is determined that the communication device does not store the first identification code, a topic registration request is sent to the topic registration server, wherein the topic registration request is used to request the registration of the first identification code corresponding to the second message topic;

[0110] S6, receive the first identification code sent by the topic registration server, generate a second message based on the first identification code and the message to be sent, and send the second message to the message middleware to instruct the message middleware to distribute the second message to the second subscription device that has subscribed to the second message topic.

[0111] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.

[0112] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated here.

[0113] Obviously, those skilled in the art should understand that the modules or steps of this application described above can be implemented using general-purpose computing systems. They can be centralized on a single computing system or distributed across a network of multiple computing systems. Optionally, they can be implemented using program code executable by a computing system, thereby storing them in a storage system for execution by the computing system. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, this application is not limited to any particular combination of hardware and software.

[0114] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.

Claims

1. A method of registering a message topic, characterized by, The application is applied to a theme registration server, comprising: In the case of receiving a theme registration request sent by a communication device, it is determined whether a second message theme corresponding to the theme registration request has been registered; In the case of determining that the second message theme has not been registered, a first identification code corresponding to the second message theme is randomly generated, wherein the first identification code is used to uniquely identify the second message theme; The corresponding relationship between the second message theme and the first identification code is saved, and the first identification code is sent to the communication device.

2. The message topic registration method of claim 1, wherein, After saving the corresponding relationship between the second message theme and the first identification code and sending the first identification code to the communication device, the method further comprises: In the case of receiving an identification code conversion request sent by a message middleware, a second identification code carried by the identification code conversion request is obtained; In response to the identification code conversion request, a first message theme corresponding to the second identification code is matched in mapping data, wherein the mapping data is used to indicate a one-to-one correspondence between a plurality of identification codes and a plurality of message themes; The first message theme is sent to the message middleware to instruct the message middleware to distribute a first message corresponding to the second identification code to a first subscription device that has subscribed to the first message theme according to the first message theme.

3. The message topic registration method of claim 1, wherein, After determining whether the second message theme corresponding to the theme registration request has been registered, the method further comprises: In the case of determining that the second message theme has been registered, the first identification code corresponding to the second message theme is queried in mapping data saved by the theme registration server, wherein the mapping data is used to indicate a one-to-one correspondence between a plurality of identification codes and a plurality of message themes; The first identification code is sent to the communication device.

4. The message topic registration method of claim 1, wherein, Randomly generating the first identification code corresponding to the second message theme comprises: Determining the number of identification codes of a plurality of identification codes registered by the theme registration server, and determining the first length of the maximum identification code in the plurality of identification codes; Obtaining a quantity threshold value corresponding to the first length, and determining whether the number of identification codes is greater than the quantity threshold value; In the case that the number of identification codes is less than the quantity threshold value, the first identification code is randomly generated according to the first length; In the case that the number of identification codes is greater than or equal to the quantity threshold value, a second length is determined according to the first length, and the first identification code is randomly generated according to the second length, wherein the second length is greater than the first length.

5. A message sending method characterized by, The application is applied to a communication device, comprising: In the case of determining that the communication device has a to-be-sent message, it is determined whether the communication device stores a first identification code of a second message theme corresponding to the to-be-sent message, wherein the first identification code is used to uniquely identify the second message theme; In the case of determining that the communication device does not store the first identification code, a theme registration request is sent to a theme registration server, wherein the theme registration request is used to request to register the first identification code corresponding to the second message theme; receive the first identification code sent by the topic registration server, generate a second message according to the first identification code and the to-be-sent message, and send the second message to the message middleware to instruct the message middleware to distribute the second message to a second subscription device that has subscribed to the second message topic.

6. The message sending method of claim 5, wherein, After determining whether the communication device stores the first identification code of the second message topic corresponding to the to-be-sent message, the method further includes: generating the second message according to the first identification code and the to-be-sent message in a case where it is determined that the communication device stores the first identification code; sending the second message to the message middleware.

7. An apparatus for registering a message topic, characterized by comprise: a first determination module configured to determine, in a case where a topic registration request sent by a communication device is received, whether a second message topic corresponding to the topic registration request has been registered; a generation module configured to generate, in a case where it is determined that the second message topic has not been registered, a first identification code corresponding to the second message topic randomly, wherein the first identification code is used to uniquely identify the second message topic; a first sending module configured to save a correspondence between the second message topic and the first identification code, and send the first identification code to the communication device.

8. A message sending apparatus characterized by comprising: comprise: a second determination module configured to determine, in a case where it is determined that a communication device has a to-be-sent message, whether the communication device stores a first identification code of a second message topic corresponding to the to-be-sent message, wherein the first identification code is used to uniquely identify the second message topic; a second sending module configured to send, in a case where it is determined that the communication device does not store the first identification code, a topic registration request to a topic registration server, wherein the topic registration request is used to request registration of the first identification code corresponding to the second message topic; a third sending module configured to receive the first identification code sent by the topic registration server, generate a second message according to the first identification code and the to-be-sent message, and send the second message to the message middleware to instruct the message middleware to distribute the second message to a second subscription device that has subscribed to the second message topic.

9. A computer readable storage medium, characterized in that, The computer-readable storage medium comprises a stored program, wherein the program, when executed, performs the method of any one of claims 1 to 4 or 5 to 6. 10.An electronic device comprising a memory and a processor, the electronic device characterized by, The memory stores a computer program, and the processor is configured to execute the method of any one of claims 1 to 4 or 5 to 6 by using the computer program.