Information transmission method and device, server and storage medium
By deploying a first node and a second node in the MQTT server, storing only local routing information and forwarding requests, the problem of excessive resource consumption in cross-node message transmission is solved, achieving more efficient resource utilization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN HEYTAP TECHNOLOGY CO LTD
- Filing Date
- 2022-10-26
- Publication Date
- 2026-07-14
AI Technical Summary
In the scenario of cross-node message publishing using the MQTT protocol, existing technologies require each node to cache a large amount of routing information, resulting in excessive resource consumption and limiting the cluster size and service capabilities.
By deploying a first node and multiple second nodes in an MQTT server, the first node stores only the routing information of the devices it connects to, and the second nodes store only the topics that their devices subscribe to. The first node is responsible for forwarding topic publishing requests and messages, thus reducing the sharing of routing information between nodes.
This reduces the amount of data cached on the MQTT server, lowers resource consumption, and improves system scalability and efficiency.
Smart Images

Figure CN117938844B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of Internet of Things (IoT) technology, and more specifically, to an information transmission method, apparatus, server, and storage medium. Background Technology
[0002] With the rapid advancement of technology, the Internet of Things (IoT) has been widely applied in fields such as smart homes, artificial intelligence, connected vehicles, energy, and industrial manufacturing. As the core platform for IoT device management, the IoT platform relies on device connectivity services as a bridge for communication between the platform and devices. Message Queuing Telemetry Transport (MQTT) is a secure and stable far-field IoT connectivity protocol, widely used in device connectivity services due to its stability, reliability, and resilience to weak network conditions. However, when implementing cross-node message publishing scenarios, MQTT connectivity service clusters require each node to cache a large amount of routing information, thus consuming significant resources. Summary of the Invention
[0003] This application proposes an information transmission method, apparatus, server, and storage medium that can reduce the amount of data cached when an MQTT server is used in a scenario of publishing messages across nodes.
[0004] In a first aspect, embodiments of this application provide an information transmission method applied to a Message Queuing Telemetry Transmission (MQTT) server. The MQTT server deploys a first node and multiple second nodes connected to the first node. The method includes: receiving a topic publication request from a first target device connected to the first target node via a first target node. The topic publication request requests the publication of a topic message for a target topic. The first target node is any one of the multiple second nodes, and the first target device is any one of the devices connected to the first target node. The first target node, based on the topic publication request, sends the topic message to devices among the devices connected to the first target node that have subscribed to the target topic, and also sends the topic publication request to the first node. The first node sends the topic publication request to a second target node, where the second target node is a node other than the first target node among the multiple second nodes, and at least one device among the devices connected to the second target node has subscribed to the target topic. The second target node, based on the topic publication request, sends the topic message to devices among the devices connected to the second target node that have subscribed to the target topic.
[0005] Secondly, embodiments of this application provide an information transmission device applied to a Message Queuing Telemetry Transmission (MQTT) server. The MQTT server deploys a first node and multiple second nodes connected to the first node. The device includes: a request receiving module, a first sending module, a second sending module, and a third sending module. The request receiving module is used to receive a topic publishing request sent by a first target device connected to the first target node through a first target node. The topic publishing request is used to request the publishing of a topic message for a target topic. The first target node is any one of the multiple second nodes, and the first target device is any one of the devices connected to the first target node. The first sending module is used to... The first target node sends the topic message to devices connected to the first target node that have subscribed to the target topic based on the topic publishing request, and also sends the topic publishing request to the first node; the second sending module is used to send the topic publishing request to a second target node through the first node, wherein the second target node is a node other than the first target node among the plurality of second nodes, and at least one device connected to the second target node has subscribed to the target topic; the third sending module is used to send the topic message to devices connected to the second target node that have subscribed to the target topic based on the topic publishing request through the second target node.
[0006] Thirdly, embodiments of this application provide an electronic device, including: one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more application programs are configured to perform the information transmission method provided in the first aspect above.
[0007] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code, which can be invoked by a processor to execute the information transmission method provided in the first aspect above.
[0008] The solution provided in this application involves an MQTT server deploying a first node and multiple second nodes connected to the first node. The first target node receives a topic publication request from a first target device connected to the target node. This topic publication request requests the publication of a topic message for a target topic. The first target node is any one of the multiple second nodes, and the first target device is any one of the devices connected to the first target node. Based on the topic publication request, the first target node sends the topic message to devices connected to the first target node that have subscribed to the target topic, and also sends the topic publication request back to the first node. The first node then sends the topic publication request to a second target node, which is any one of the multiple second nodes other than the first target node, and at least one device connected to the second target node has subscribed to the target topic. Finally, based on the topic publication request, the second target node sends the topic message to devices connected to the second target node that have subscribed to the target topic. Therefore, when the MQTT server implements cross-node information transmission, each of the above second nodes only needs to publish the topic message to the devices connected to that second node and subscribed to the target topic according to the topic publication request, and forward the topic publication request to the first node. The first node then forwards the topic publication request to other second nodes to publish it to the devices connected to other second nodes and subscribed to the target topic. Thus, each first node only needs to store the routing information of the devices it is connected to, without having to maintain the routing information of the devices connected to the second nodes. This reduces the data caching of the MQTT server and lowers resource consumption. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A schematic diagram of the architecture of a simple multi-node model cluster in related technologies is shown.
[0011] Figure 2 A schematic diagram of the application environment provided in the embodiments of this application is shown.
[0012] Figure 3 A flowchart of an information transmission method according to an embodiment of this application is shown.
[0013] Figure 4 A flowchart of an information transmission method according to another embodiment of this application is shown.
[0014] Figure 5A flowchart of an information transmission method according to yet another embodiment of this application is shown.
[0015] Figure 6 A block diagram of an information transmission apparatus according to an embodiment of this application is shown.
[0016] Figure 7 This is a block diagram of a server used to perform an information transmission method according to an embodiment of this application.
[0017] Figure 8 It is a storage unit in this application embodiment for storing or carrying program code that implements the information transmission method according to this application embodiment. Detailed Implementation
[0018] 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.
[0019] Currently, the MQTT protocol, as a secure and stable far-field IoT connectivity protocol, is widely used as the connectivity protocol in device connectivity services due to its stability, reliability, and resistance to weak network conditions. Generally, connectivity services consist of three main modules: a protocol parsing layer, a message storage layer, and a message routing layer, used to implement device access, uplink and downlink message caching, and message distribution control functions for the IoT platform.
[0020] Existing MQTT-based connection services primarily fall into two architectures: the monolithic software model and the simple multi-node model. The monolithic software model consists of a single software module, meaning the three modules of the connection service run within the same process. This lacks horizontal and vertical scalability, making it unsuitable for applications with massive device connections. Please refer to [link / reference]. Figure 1 , Figure 1 The diagram illustrates the architecture of a simple multi-node cluster model. In this model, all nodes synchronize device connections and topic subscription information, enabling cross-node message subscription and publication within the cluster. The simple multi-node cluster model can handle scenarios with massive device connections, and therefore, current connection service architectures primarily employ this model. However, to cope with scenarios with massive device connections, each node in the simple multi-node model must cache a massive amount of routing information. This results in multiple nodes needing to cache a large amount of routing information, thus limiting the cluster's scale and service capabilities in terms of resources.
[0021] To address the aforementioned problems, the inventors have proposed an information transmission method, apparatus, server, and storage medium as described in this application. When an MQTT server implements cross-node information transmission, each second node only needs to publish a topic message to devices connected to that second node and subscribed to the target topic, and forward the topic publication request to the first node. The first node then forwards the topic publication request to other second nodes to publish it to devices connected to other second nodes and subscribed to the target topic. Thus, each first node only needs to store the routing information of the devices it connects to, without needing to maintain shared routing information for all second nodes, thereby reducing the data caching load of the MQTT server and lowering resource consumption. The specific information transmission method will be described in detail in subsequent embodiments.
[0022] The scenarios involved in the embodiments of this application will be introduced below.
[0023] like Figure 2 As shown, in Figure 2 The scenario shown includes an MQTT server 10, which deploys a first node 11 and multiple second nodes 12 connected to the first node. Figure 2 (Only 3 are shown in the image). The second node 12 is used to connect to the IoT device 20 and cache the routing information of the connected IoT device 20. Based on the cached routing information, the second node 12 can distribute topic messages to the connected IoT devices 20 that have subscribed to the topic. The first node 11 is used to cache the routing information of the IoT devices 20 connected to each second node 12, so as to forward the topic messages sent by the second node 12 to the corresponding other second nodes 12, and the other second nodes 12 forward the topic messages to the connected IoT devices 20 that have subscribed to the topic. This realizes cross-node information transmission, and there is no need for each second node 12 to share the routing information of the connected IoT devices 20, thereby reducing the data caching amount of the MQTT server 10 and reducing resource consumption.
[0024] The information transmission method provided in the embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0025] Please see Figure 3 , Figure 3 A flowchart illustrating an embodiment of the information transmission method provided in this application is shown. In a specific embodiment, the information transmission method is applied to the aforementioned MQTT server, which deploys a first node and multiple second nodes connected to the first node. The following will focus on... Figure 3 The process shown will be described in detail. The information transmission method may specifically include the following steps:
[0026] Step S110: Receive a topic publishing request sent by a first target device connected to the first target node through the first target node. The topic publishing request is used to request the publishing of a topic message for a target topic. The first target node is any one of the plurality of second nodes, and the first target device is any one of the devices connected to the first target node.
[0027] In this cluster, the first and second nodes can be processes created within the MQTT server. The first node and multiple second nodes connected to it can be considered a connection service cluster. Its basic function is to forward and deliver messages published by the message publisher to message subscribers connected to each second node. Second nodes and the first node communicate and address each other via node names. After multiple second nodes and the first node form a connection service cluster, each second node establishes a TCP-based connection with the first node. Of course, when a new second node joins the connection service cluster, it will also establish a TCP-based connection with the first node. Each second node can establish long-lived connections with connected devices based on the MQTT protocol. The devices connected to each second node are not limited; for example, they can be home appliances, mobile terminals, etc.
[0028] In this embodiment, any second node (as the first target node) among a plurality of second nodes can receive a topic publishing request sent by any device connected to it (as the first target device), so as to send the topic message of the target topic requested by the first target device to devices connected to the first target node that have subscribed to the target topic, and to send the topic message to other second nodes that have subscribed to the target topic. It should be noted that since the first target node is any second node and the first target device is any device connected to the first target node, any topic publishing request received by any second node from its connected devices can be published to all devices that have subscribed to the target topic according to the message transmission method provided in this embodiment.
[0029] In some implementations, the target topic can be any topic created in the MQTT server, and the topic message can be a message corresponding to the target topic. For example, if the target topic is ambient temperature, the topic message can be the ambient temperature value. IoT devices that need to be controlled based on ambient temperature can subscribe to the ambient temperature topic, and devices collecting ambient temperature data can publish the topic message for that ambient temperature topic. This allows IoT devices that have subscribed to the ambient temperature topic to obtain the collected ambient temperature value and perform device control based on that value. Of course, the above target topics and topic messages are merely examples, and specific target topics and topic messages are not limited to a single example.
[0030] Step S120: Based on the topic publishing request, the first target node sends the topic message to the devices that have subscribed to the target topic among the devices connected to the first target node, and sends the topic publishing request to the first node.
[0031] In this embodiment of the application, when the first target node receives the topic publishing request, the first target node can send the topic message to the devices that have subscribed to the target topic in the devices connected to the first target node, and send the topic publishing request to the first node, so that the first node can send the topic publishing request to other second nodes, thereby enabling the other second nodes to send the topic message to the devices that have subscribed to the target topic in the devices connected to them, thereby realizing the publication of the topic message to all devices that have subscribed to the target topic.
[0032] In some implementations, each second node can cache the first routing information of the devices it connects to. The first routing information may include information about the connected devices (such as device identifiers) and the topics subscribed to by each connected device. Of course, the specific first routing information is not limited. Thus, after receiving the topic publishing request, the first target node can send the topic message to the devices among the devices connected to the first target node that have subscribed to the target topic, based on its cached first routing information.
[0033] Step S130: Send the topic publishing request to the second target node through the first node. The second target node is a node other than the first target node among the plurality of second nodes, and at least one device among the devices connected to the second target node has subscribed to the target topic.
[0034] In this embodiment of the application, after receiving the topic publishing request sent by the first target node, the first node can forward the topic publishing request and send it to the second target node connected to the device that has subscribed to the target topic in the other second nodes, so that the second target node can send the topic message to the device that has subscribed to the target topic in the device connected to the second target node based on the received topic publishing request.
[0035] In some implementations, the first node can cache the second routing information of all second nodes. This second routing information may include the devices connected to each second node, the topics subscribed to by each connected device, etc. Of course, the specific routing information is not limited. Therefore, after receiving the topic publishing request, the first node can determine the second target node based on its cached second routing information and send the topic message to the second target node.
[0036] Step S140: Based on the topic publishing request, the second target node sends the topic message to the devices that have subscribed to the target topic among the devices connected to the second target node.
[0037] In this embodiment, after the second target node receives the topic publishing request, it can send the topic message requested in the request to devices connected to it that have subscribed to the target topic. Specifically, the second target node can determine which devices connected to it have subscribed to the target topic based on its cached first routing information and send the topic message to those devices. Therefore, after the first and second target nodes send the topic message to their respective connected devices that have subscribed to the target topic, it is possible to send the topic message to all devices that have subscribed to the target topic.
[0038] The information transmission method provided in this application embodiment allows the MQTT server to implement cross-node information transmission. Each of the above second nodes only needs to publish the topic message to the device connected to the second node and subscribed to the target topic according to the topic publication request, and forward the topic publication request to the first node. The first node then forwards the topic publication request to other second nodes to publish it to the device connected to the other second nodes and subscribed to the target topic. Thus, each first node only needs to store the topics subscribed to by the devices it is connected to, without having to maintain the topics subscribed to by the devices shared by each second node (that is, each second node does not need to store the topics subscribed to by the devices connected to other second nodes), thereby reducing the data cache of the MQTT server and reducing resource consumption.
[0039] Please see Figure 4 , Figure 4 A flowchart illustrating an information transmission method according to another embodiment of this application is shown. This information transmission method is applied to the aforementioned MQTT server, which deploys a first node and multiple second nodes connected to the first node. The following will focus on... Figure 4 The process shown will be described in detail. The information transmission method may specifically include the following steps:
[0040] Step S210: Receive a topic publishing request sent by a first target device connected to the first target node through the first target node. The topic publishing request is used to request the publishing of a topic message for a target topic. The first target node is any one of the plurality of second nodes, and the first target device is any one of the devices connected to the first target node.
[0041] In this embodiment, step S210 can be referred to the content of other embodiments, and will not be repeated here.
[0042] Step S220: Based on the first mapping relationship stored by the first target node, determine the second target device among the devices connected to the first target node that has subscribed to the target topic.
[0043] In this embodiment, each second node stores a first mapping relationship corresponding to each device among its connected devices. This first mapping relationship includes the mapping relationship between each device and its subscribed topics; that is, the second node stores the topics subscribed to by each device among its connected devices. Therefore, upon receiving the topic publishing request, the first target node can respond to the request, determine the devices among its connected devices that have subscribed to the target topic based on the target topic requested in the request and the first mapping relationship stored by the first target node, and designate the devices subscribed to the target topic as second target devices.
[0044] Step S230: The first target node sends the topic message to the second target device based on the topic publishing request, and sends the topic publishing request to the first node.
[0045] In this embodiment, after determining the second target device, the first target node can send the topic message corresponding to the target topic requested to be published by the topic publishing request to the second target device, and send the topic publishing request to the first node, so that the first node can send the topic publishing request to other second nodes, thereby enabling the other second nodes to send the topic message to the devices that have subscribed to the target topic among the devices connected to them, thus realizing the publication of the topic message to all devices that have subscribed to the target topic.
[0046] Step S240: Based on the second mapping relationship, the first node determines the second target node as the second target node from the other nodes among the plurality of second nodes that have a mapping relationship with the target topic.
[0047] In this embodiment, the first node stores a second mapping relationship corresponding to each second node. This second mapping relationship includes the mapping relationship between the second node and all topics subscribed to by the devices connected to it. In other words, the first node only needs to record the mapping relationship between the second node and the topics. For example, if a second node is connected to devices 1 and 2, and device 1 subscribes to topics A and B, while device 2 subscribes to topics A and C, then the first node only needs to determine all topics subscribed to by the devices connected to it (i.e., topics A, B, and C) and record the mapping relationship between the second node and topics A, B, and C. Based on this, after receiving the topic publishing request, the first node can, based on the target topic requested in the topic publishing request and the stored second mapping relationship, determine the second node with a mapping relationship to the target topic from among the other nodes (excluding the first target node) and use the determined second node as the second target node.
[0048] Step S250: Send the topic publishing request to the second target node through the first node.
[0049] In this embodiment of the application, after the first node determines the second target node, it can forward the topic publishing request and send the topic publishing request to the determined second target node, so that the second target node can send the topic message to the devices that have subscribed to the target topic in the device connected to the second target node based on the received topic publishing request.
[0050] Step S260: Based on the topic publishing request, the second target node sends the topic message to the devices that have subscribed to the target topic among the devices connected to the second target node.
[0051] In this embodiment, after receiving the topic publishing request, the second target node can also determine the devices among its connected devices that have subscribed to the target topic based on its stored first mapping relationship and the target topic requested in the publishing request. After determining the subscribed devices, the second target node sends the topic message corresponding to the target topic requested in the publishing request to the determined subscribed devices. Thus, after the first and second target nodes send the topic message to the subscribed devices among their respective connected devices, the sending of the topic message to all devices subscribed to the target topic is completed.
[0052] The information transmission method provided in this application embodiment enables cross-node information transmission by deploying a first node and multiple second nodes connected to the first node on the MQTT server. The first node stores the mapping relationship between all topics subscribed to by each second node and the devices connected to each second node. Each second node only needs to maintain the mapping relationship between each device connected to it and the subscribed topics. Therefore, it is not necessary to maintain the subscribed topics of the devices connected to each second node (that is, each second node does not need to store the topics subscribed to by the devices connected to other second nodes), thereby reducing the data cache of the MQTT server and reducing resource consumption.
[0053] Please see Figure 5 , Figure 5 A flowchart illustrating an information transmission method according to another embodiment of this application is shown. This information transmission method is applied to the aforementioned MQTT server, which deploys a first node and multiple second nodes connected to the first node. The following will focus on... Figure 5 The process shown will be described in detail. The information transmission method may specifically include the following steps:
[0054] Step S300: Receive a topic subscription request sent by the second target device through the first target node. The topic subscription request is used to request subscription to the target topic.
[0055] In this embodiment, each second node stores a first mapping relationship corresponding to each device among the devices it is connected to, the first mapping relationship including the mapping relationship between each device and the subscribed topics; the first node stores a second mapping relationship corresponding to each second node, the second mapping relationship including the mapping relationship between the second node and all topics subscribed to by the devices connected to the second node.
[0056] In this embodiment, the second target device can send a topic subscription request to the first target node to subscribe to a target topic, so that after subscribing to the target topic, it can receive topic messages published for that target topic. Correspondingly, the first target node can receive a topic publishing request sent by the second target device.
[0057] Step S310: Add the mapping relationship between the second target device and the target topic to the first mapping relationship corresponding to the second target device through the first target node.
[0058] In this embodiment, after the first target node receives a topic subscription request from the second target device, it can respond to the request by adding the mapping relationship between the second target device and the target topic to the first mapping relationship corresponding to the second target device. Therefore, if either device sends a topic publishing request for the target topic, the first target node can send the topic message of the target topic to the second target device according to its stored first mapping relationship.
[0059] It should be noted that since the first target node is any second node and the target topic is any topic, any device can subscribe to any topic in the above manner when it needs to subscribe to any topic. That is, the device sends a topic subscription request corresponding to the topic to be subscribed to to the second node it is connected to. After receiving the topic subscription request, the second node can add the mapping relationship between the device and the topic to be subscribed to to the first mapping relationship stored in the second node.
[0060] In some implementations, after receiving the topic subscription request, the first target node can parse the topic subscription request. If the parsing fails, or if the parsing is successful but authentication fails based on the authentication information in the parsed parameters, a first subscription result can be returned to the second target device. This first subscription result indicates that the subscription to the target topic has failed. If the parsing is successful and authentication is successful based on the authentication information in the parsed parameters, the mapping relationship between the second target device and the target topic can be added to the first mapping relationship corresponding to the second target device, and a second subscription result can be returned to the second target device. This second subscription result indicates that the subscription to the target topic has been successful.
[0061] In some implementations, each second node creates a first connection cache corresponding to each device it connects to. The first connection cache stores the first mapping relationship corresponding to the device in the first connection cache. Upon receiving an access request from a new device, any second node can create a first connection cache corresponding to the new device in response to the access request. Optionally, the second node can request a cache space of a preset size and use it as the first connection cache corresponding to the new device.
[0062] In one possible implementation, upon receiving an access request from a new device, the second node can parse connection parameters such as keep-alive time, permissions, and protocol version from the access request; then verify the validity of the connection parameters; if valid, a first connection cache corresponding to the new device is created, and a first access result is returned to the new device, indicating successful access; if invalid, a second access result is returned to the new device, indicating access failure. Verifying the validity of the connection parameters may include at least one of the following conditions: the keep-alive time does not exceed the maximum value, the permission information is accurate, and the protocol version is supported.
[0063] Step S320: Receive the third mapping relationship sent by the third target node through the first node.
[0064] The third mapping relationship includes the mapping relationship between the device connected to the third target node and the target topic. The third mapping relationship is sent by the device connected to the third target node when it requests to subscribe to the target topic. The third target node is any one of the plurality of second nodes.
[0065] In this embodiment of the application, when a device connected to any of the multiple second nodes (as the third target node) requests to subscribe to a target topic, the third target node can also send the above third mapping relationship to the first node so that the first node can synchronously update the second mapping relationship it stores, so that the first node can send the topic publishing request of the target topic to the third target node according to the second mapping relationship.
[0066] Step S330: Based on the third mapping relationship, the first node adds the mapping relationship between the third target node and the target topic to the second mapping relationship corresponding to the third target node.
[0067] In this embodiment of the application, after the first node receives the above third mapping relationship, since the third mapping relationship indicates that the device connected to the above third target node has subscribed to the target topic, the mapping relationship between the third target node and the target topic can be added to the second mapping relationship corresponding to the third target node, so that the first node can send the topic publishing request of the target topic to the third target node according to the second mapping relationship.
[0068] It should be noted that, since the third target node is any second node and the target topic is any topic, when any device subscribes to any topic through the connected second node, it can send the mapping relationship between the device and the topic to the first node in the above manner. The first node updates the second mapping relationship corresponding to the second node stored in its storage according to the received mapping relationship.
[0069] In some implementations, the first node creates a second connection cache corresponding to each second node. This second connection cache stores the second mapping relationship corresponding to the second node. When a new second node needs to be added, the new second node can send a join request to the first node. Correspondingly, the first node can receive the join request and then respond to it by creating a new second connection cache corresponding to the new second node. Optionally, the first node can request a cache space of a target size and use it as the second connection cache corresponding to the new second node.
[0070] In one possible implementation, when the first node receives a join request from a new second node, it can parse the join request. If parsing fails, or if parsing succeeds but authentication fails based on the authentication information in the parsed parameters, the first node can return a first join result to the new second node, which indicates that the join to the connection service cluster was unsuccessful. If parsing succeeds and authentication succeeds based on the authentication information in the parsed parameters, the first node can create a new second connection cache corresponding to the second node and return a second join result to the new second node, which indicates that the join to the connection service cluster was successful.
[0071] In one possible implementation, the first node can also manage multiple second nodes to reduce the cache space occupied. Optionally, the first node can detect second nodes that are not connected to any devices; when a fourth target node is detected to be not connected to any devices, the first node can start timing the state of the fourth target node remaining unconnected to any devices, where the fourth target node is any second node; if the timing reaches a preset duration, the connection with the fourth target node can be disconnected and the second connection cache corresponding to the fourth target node can be deleted. The specific value of the preset duration is not limited, for example, it can be 1 day, 7 days, 30 days, etc. This allows for the cleanup of idle second nodes, reducing resource consumption.
[0072] Step S340: Receive a topic publishing request sent by a first target device connected to the first target node through the first target node. The topic publishing request is used to request the publishing of a topic message for a target topic. The first target node is any one of the plurality of second nodes, and the first target device is any one of the devices connected to the first target node.
[0073] Step S350: Based on the first mapping relationship stored by the first target node, determine the second target device among the devices connected to the first target node that has subscribed to the target topic.
[0074] Step S360: The first target node sends the topic message to the second target device based on the topic publishing request, and sends the topic publishing request to the first node.
[0075] Step S370: Based on the second mapping relationship, the first node determines the second target node as the second target node from the other nodes among the plurality of second nodes that have a mapping relationship with the target topic.
[0076] Step S380: Send the topic posting request to the second target node through the first node.
[0077] Step S390: Based on the topic publishing request, the second target node sends the topic message to the devices that have subscribed to the target topic among the devices connected to the second target node.
[0078] In this embodiment, steps S340 to S390 can be referred to the content of the foregoing embodiments, and will not be repeated here.
[0079] The information transmission method provided in this application embodiment enables cross-node information transmission by deploying a first node and multiple second nodes connected to the first node on the MQTT server. The first node creates a connection cache for each second node to store the mapping relationship between all topics subscribed to by each second node and the devices connected to each second node. Each second node creates a connection cache for each connected device to cache the mapping relationship between each connected device and the subscribed topics. Thus, it is not necessary to maintain the subscribed topics of the devices connected to each second node (that is, each second node does not need to store the topics subscribed to by the devices connected to other second nodes), thereby reducing the data cache size of the MQTT server and reducing resource consumption.
[0080] Please see Figure 6 The diagram illustrates a structural block diagram of an information transmission device 400 provided in an embodiment of this application. The information transmission device 400 utilizes the aforementioned MQTT server, which deploys a first node and multiple second nodes connected to the first node. The information transmission device 400 includes: a request receiving module 410, a first sending module 420, a second sending module 430, and a third sending module 440. The request receiving module 410 is configured to receive a topic publishing request sent by a first target device connected to the first target node through a first target node. The topic publishing request is used to request the publishing of a topic message for a target topic. The first target node is any one of the plurality of second nodes, and the first target device is any one of the devices connected to the first target node. The first sending module 420 is configured to send the topic message to devices connected to the first target node that have subscribed to the target topic based on the topic publishing request through the first target node, and also send the topic publishing request to the first node. The second sending module 430 is configured to send the topic publishing request to a second target node through the first node. The second target node is a node other than the first target node among the plurality of second nodes, and at least one device connected to the second target node has subscribed to the target topic. The third sending module 440 is configured to send the topic message to devices connected to the second target node that have subscribed to the target topic based on the topic publishing request through the second target node.
[0081] In some implementations, each second node stores a first mapping relationship for each device among the devices it connects to, the first mapping relationship including the mapping relationship between each device and the subscribed topic. The first sending module 420 may be specifically configured to: determine, based on the first mapping relationship stored by the first target node, a second target device among the devices connected to the first target node that has subscribed to the target topic; and send the topic message to the second target device based on the topic publishing request by the first target node.
[0082] In one possible implementation, the information transmission device 400 may further include a first relationship addition module. The request receiving module 410 may also be configured to receive a topic subscription request sent by the second target device through the first target node before determining, through the first target node and based on the first mapping relationship stored by the first target node, a second target device among the devices connected to the first target node that has subscribed to the target topic. The topic subscription request is used to request subscription to the target topic. The first relationship addition module is configured to add the mapping relationship between the second target device and the target topic to the first mapping relationship corresponding to the second target device through the first target node.
[0083] In one possible implementation, each of the second nodes creates a first connection cache corresponding to each device it connects to. The first connection cache stores the first mapping relationship corresponding to the device corresponding to the first connection cache. The information transmission device 400 may further include a first cache creation module. The first cache creation module is used to create the first connection cache corresponding to the new device in response to an access request from the second node.
[0084] In some implementations, the first node stores a second mapping relationship corresponding to each second node, the second mapping relationship including the mapping relationship between the second node and all topics subscribed to by the devices connected to the second node. The second sending module 430 may be specifically used to: determine, based on the second mapping relationship, from the plurality of second nodes other than the first target node, a second node that has a mapping relationship with the target topic as the second target node; and send the topic publishing request to the second target node through the first node.
[0085] In one possible implementation, the information transmission device 400 may further include a mapping receiving module and a second relationship adding module. The mapping receiving module is used to receive a third mapping relationship sent by a third target node through the first node. The third mapping relationship includes a mapping relationship between the device connected to the third target node and the target topic. The third mapping relationship is sent by the device connected to the third target node when requesting to subscribe to the target topic. The third target node is any one of the plurality of second nodes. The second relationship adding module is used by the first node to add the mapping relationship between the third target node and the target topic to the second mapping relationship corresponding to the third target node based on the third mapping relationship.
[0086] In one possible implementation, the first node creates a second connection cache corresponding to each second node, the second connection cache being used to store the second mapping relationship corresponding to the second node. The information transmission device 400 may further include a second cache creation module. The request receiving module 410 may also be used to receive a new second node's join request through the first node; the second cache creation module is used to create the second connection cache corresponding to the new second node in response to the join request through the first node.
[0087] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0088] In the several embodiments provided in this application, the coupling between modules can be electrical, mechanical, or other forms of coupling.
[0089] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0090] In summary, the solution provided in this application involves an MQTT server deploying a first node and multiple second nodes connected to the first node. The first target node receives a topic publication request from a first target device connected to the target node. This topic publication request requests the publication of a topic message for a target topic. The first target node is any one of the multiple second nodes, and the first target device is any one of the devices connected to the first target node. Based on the topic publication request, the first target node sends the topic message to devices connected to the first target node that have subscribed to the target topic, and also sends the topic publication request back to the first node. The first node then sends the topic publication request to a second target node, which is any one of the multiple second nodes other than the first target node, and at least one device connected to the second target node has subscribed to the target topic. Finally, based on the topic publication request, the second target node sends the topic message to devices connected to the second target node that have subscribed to the target topic. Therefore, when the MQTT server implements cross-node information transmission, each of the above second nodes only needs to publish the topic message to the devices connected to that second node and subscribed to the target topic according to the topic publication request, and forward the topic publication request to the first node. The first node then forwards the topic publication request to other second nodes to publish it to the devices connected to other second nodes and subscribed to the target topic. Thus, each first node only needs to store the routing information of the devices it is connected to, without having to maintain the routing information of the devices connected to the second nodes. This reduces the data caching of the MQTT server and lowers resource consumption.
[0091] Please refer to Figure 7 This diagram illustrates a structural block diagram of a server provided in an embodiment of this application. The server 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications may be stored in the memory 120 and configured to be executed by the one or more processors 110, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.
[0092] Processor 110 may include one or more processing cores. Processor 110 connects to various parts within server 100 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 120, and by calling data stored in memory 120. Optionally, processor 110 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 110 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 110 and may be implemented separately using a communication chip.
[0093] The memory 120 may include random access memory (RAM) or read-only memory (ROM). The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the server 100 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0094] Please refer to Figure 8 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 800 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0095] The computer-readable storage medium 800 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 800 has storage space for program code 810 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 810 may be compressed, for example, in a suitable form.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. An information transmission method, characterized in that, An application to a Message Queuing Telemetry Transport (MQTT) server, wherein the MQTT server deploys a first node and multiple second nodes connected to the first node, the method comprising: The first target node receives a topic publishing request sent by a first target device connected to the first target node. The topic publishing request is used to request the publishing of a topic message for a target topic. The first target node is any one of the plurality of second nodes, and the first target device is any one of the devices connected to the first target node. Based on the topic publishing request, the first target node sends the topic message to devices that have subscribed to the target topic among the devices connected to the first target node, and sends the topic publishing request to the first node; The topic publishing request is sent from the first node to the second target node, where the second target node is a node other than the first target node among the plurality of second nodes, and at least one device connected to the second target node has subscribed to the target topic; The second target node sends the topic message to devices that have subscribed to the target topic within the devices connected to the second target node, based on the topic publishing request. The first node stores the second mapping relationship corresponding to each of the second nodes; Sending the topic posting request to the second target node through the first node includes: Based on the second mapping relationship, the first node determines the second target node as the second target node from among the other nodes (excluding the first target node) that have a mapping relationship with the target topic. The topic posting request is sent to the second target node through the first node.
2. The method according to claim 1, characterized in that, Each of the second nodes stores a first mapping relationship for each device among the devices it is connected to, the first mapping relationship including the mapping relationship between each device and the subscribed topic; The step of sending the topic message to devices that have subscribed to the target topic among the devices connected to the first target node based on the topic publishing request via the first target node includes: Based on the first mapping relationship stored in the first target node, the second target device among the devices connected to the first target node that has subscribed to the target topic is determined. The first target node sends the topic message to the second target device based on the topic publishing request.
3. The method according to claim 2, characterized in that, Before determining, through the first target node and based on the first mapping relationship stored by the first target node, a second target device among the devices connected to the first target node that has subscribed to the target topic, the method further includes: The first target node receives a topic subscription request sent by the second target device, the topic subscription request being used to request subscription to the target topic; The mapping relationship between the second target device and the target topic is added to the first mapping relationship corresponding to the second target device through the first target node.
4. The method according to claim 2, characterized in that, Each of the second nodes creates a first connection cache corresponding to each device it connects to, the first connection cache being used to store the first mapping relationship corresponding to the device corresponding to the first connection cache, the method further comprising: In response to the access request from the new device, the second node creates the first connection cache corresponding to the new device.
5. The method according to claim 1, characterized in that, The method further includes: The first node receives a third mapping relationship sent by a third target node. The third mapping relationship includes a mapping relationship between the device connected to the third target node and the target topic. The third mapping relationship is sent by the device connected to the third target node when it requests to subscribe to the target topic. The third target node is any one of the plurality of second nodes. Based on the third mapping relationship, the first node adds the mapping relationship between the third target node and the target topic to the second mapping relationship corresponding to the third target node.
6. The method according to claim 4, characterized in that, The first node creates a second connection cache corresponding to each second node. The second connection cache is used to store the second mapping relationship corresponding to the second node. The method further includes: The first node receives a request to join a new second node. The first node responds to the join request and creates the second connection cache corresponding to the new second node.
7. An information transmission device, characterized in that, An apparatus for use in a Message Queuing Telemetry Transmission (MQTT) server, wherein the MQTT server deploys a first node and multiple second nodes connected to the first node, the apparatus comprising: a request receiving module, a first sending module, a second sending module, and a third sending module, wherein... The request receiving module is used to receive a topic publishing request sent by a first target device connected to the first target node through the first target node. The topic publishing request is used to request the publishing of a topic message of a target topic. The first target node is any one of the plurality of second nodes, and the first target device is any one of the devices connected to the first target node. The first sending module is used to send the topic message to devices that have subscribed to the target topic in the devices connected to the first target node based on the topic publishing request, and to send the topic publishing request to the first node; The second sending module is used to send the topic publishing request to a second target node through the first node. The second target node is a node other than the first target node among the plurality of second nodes, and at least one device connected to the second target node has subscribed to the target topic. The third sending module is used to send the topic message to devices that have subscribed to the target topic in the devices connected to the second target node, based on the topic publishing request, through the second target node; The first node stores a second mapping relationship corresponding to each second node; the second sending module is specifically used to determine, through the first node and according to the second mapping relationship, from the other nodes among the plurality of second nodes besides the first target node, a second node that has a mapping relationship with the target topic as the second target node; and to send the topic publishing request to the second target node through the first node.
8. A server, characterized in that, include: One or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs being configured to perform the method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-6.