A message sending method and device and a storage medium

By obtaining the matching pattern of the target topic, determining all possible subscribed topics to be matched, and querying the subscribed clients from the preset topic routing table, the inefficiency and low accuracy of the MQTT Broker topic routing algorithm when handling wildcards are solved, thus achieving efficient and accurate message sending.

CN115708368BActive Publication Date: 2026-02-24CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110960421.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-20
Publication Date
2026-02-24
Estimated Expiration
2041-08-20

AI Technical Summary

Technical Problem

The existing MQTT Broker topic routing algorithm has extremely low matching efficiency when dealing with topic paths containing wildcards, resulting in low accuracy and efficiency in message sending.

Method used

By obtaining the matching pattern of the target topic, all possible subscribed topics to be matched are determined, and the subscribed clients are queried from the preset topic routing table, and control messages are sent directly to the target client.

Benefits of technology

It improves the accuracy and efficiency of message sending, and solves the problems of low efficiency and low accuracy caused by hash tables and subscription tree algorithms in existing technologies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115708368B_ABST
    Figure CN115708368B_ABST
Patent Text Reader

Abstract

The application discloses a message sending method and device and a storage medium. The method comprises the following steps: obtaining a target topic of a received control message; obtaining a matching mode corresponding to the target topic, and determining a to-be-matched subscription topic corresponding to the target topic based on the matching mode; querying a client subscribing to the to-be-matched subscription topic from a preset topic routing table, and determining the queried client as a target client; and sending the control message to the target client, so that the target client executes a control operation indicated by the control message. Through the technical solution, the accuracy and efficiency of message sending are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of Internet of Things and mobile Internet technology, and in particular to a message sending method, apparatus and storage medium. Background Technology

[0002] Message Queuing Telemetry Transport (MQTT) is a message protocol based on the publish / subscribe paradigm, designed for low-performance hardware devices and low-quality network communication. Long-connection engines in the Internet of Things (IoT) are generally implemented based on the MQTT protocol, namely MQTT Broker nodes. The core of implementing MQTT Broker is to implement MQTT topics.

[0003] Currently, the algorithms for implementing topic routing in MQTT Brokers are generally hash table algorithms and subscription trees. Hash table algorithms have extremely high matching efficiency when the topic path does not contain wildcards. However, when the topic path supports wildcards, it is necessary to traverse the entire routing table, resulting in extremely poor matching efficiency and very low message sending efficiency. Although subscription trees can solve the wildcard problem, they are memory-based routing algorithms. If a node storing subscription information fails, the accuracy of identifying subscription clients is low, which in turn leads to low message sending accuracy. Summary of the Invention

[0004] To address the aforementioned technical problems, embodiments of the present invention aim to provide a message sending method, apparatus, and storage medium. After obtaining a target topic, all possible subscribed topics corresponding to the target topic are determined. Then, clients subscribed to the target topic are directly queried from a preset topic routing table, and control messages are sent to the queried clients, thereby improving the accuracy and efficiency of message sending.

[0005] The technical solution of this invention is implemented as follows:

[0006] This invention provides a message sending method, applied to a message sending device, the method comprising:

[0007] Retrieve the target topic of the received control message;

[0008] Obtain the matching pattern corresponding to the target topic, and determine the target topic to be matched and subscribed based on the matching pattern;

[0009] From the preset topic routing table, query the clients that have subscribed to the topic to be matched, and determine the queried clients as the target clients;

[0010] The control message is sent to the target client so that the target client can execute the control operation indicated by the control message.

[0011] In the above method, determining the target topic to be matched based on the matching pattern includes:

[0012] When the matching mode is exact match, the target topic is determined as the topic to be matched and subscribed.

[0013] In the above method, determining the target topic to be matched based on the matching pattern includes:

[0014] When the matching mode is a single-level wildcard matching mode, the preset topic corresponding to each topic level is obtained from the target topic, and for each topic level, the corresponding preset topic and preset single-level wildcard are determined as the corresponding optional topic.

[0015] Arrange and combine the optional topics corresponding to different topic levels, and determine each combination obtained by the arrangement and combination as the topic to be matched and subscribed;

[0016] The preset single-layer wildcard is a wildcard used to match single-layer topics in the target topic.

[0017] In the above method, determining the target topic to be matched based on the matching pattern includes:

[0018] When the matching mode is a multi-level wildcard matching mode, the preset topic corresponding to each topic level is obtained from the target topic, and for each topic level, the corresponding preset topic and preset single-level wildcard are determined as the corresponding optional topic.

[0019] Arrange and combine the optional topics corresponding to different topic levels, and add preset multi-level wildcards after each combination.

[0020] Each combination with the aforementioned preset multi-level wildcards is identified as a full-level subscription topic;

[0021] For each topic level in the target topic, the corresponding non-full-level subscription topic is determined based on the preset multi-level wildcard and the preset single-level wildcard;

[0022] The non-full-level subscription topics and the full-level subscription topics are identified as the subscription topics to be matched;

[0023] Wherein, the preset single-layer wildcard is a wildcard used to match single-layer topics in the target topic, and the preset multi-layer wildcard is a wildcard used to match multi-layer topics in the target topic.

[0024] In the above method, determining the corresponding non-full-level subscription topic for each topic level in the target topic, based on the preset multi-level wildcard and the preset single-level wildcard, includes:

[0025] For the first topic level corresponding to the preset topic with the largest matching range in the target topic, the preset multi-level wildcard is determined as the corresponding non-full-level subscription topic;

[0026] For each topic level in the target topic that is different from the first topic level, based on the preset single-level wildcard, determine the corresponding topic options when the preset multi-level wildcard is used as the corresponding topic;

[0027] For each topic level in the target topic that is different from the first topic level, the corresponding topics can be optionally combined to determine the corresponding non-full-level subscription topic.

[0028] In the above method, the step of determining the corresponding optional topic combinations when using the preset multi-level wildcard as the corresponding topic for each topic level different from the first topic level in the target topic, based on the preset single-level wildcard, includes:

[0029] From the target topic, obtain at least one topic level with a topic level higher than the second topic level, and obtain a preset topic corresponding to each topic level; the second topic level is any topic level in the target topic that is different from the first topic level, and the matching range of the preset topics corresponding to each topic level in the at least one topic level is greater than the matching range of the preset topics corresponding to the second topic level;

[0030] For each topic level in the at least one topic level, the corresponding preset topic and the preset single-level wildcard are determined as the corresponding optional topic;

[0031] Arrange and combine the optional topics corresponding to different topic levels in the at least one topic level, and add the preset multi-level wildcard after each combination to determine the optional topic combination corresponding to the second topic level.

[0032] In the above method, sending the control message to the target client includes:

[0033] From the preset topic routing table, query the server Internet Protocol address corresponding to the target client;

[0034] The control message is forwarded to the target client via the server's Internet Protocol address.

[0035] This invention provides a message sending device, the message sending device comprising:

[0036] The acquisition module is used to acquire the target topic of the received control message;

[0037] The determining module is used to obtain the matching pattern corresponding to the target topic, and determine the target topic to be matched and subscribed based on the matching pattern;

[0038] The query module is used to query clients that have subscribed to the topic to be matched from the preset topic routing table, and to identify the queried clients as target clients;

[0039] The sending module is used to send the control message to the target client so that the target client can execute the control operation indicated by the control message.

[0040] This invention provides a message sending device, comprising: a processor, a memory, and a communication bus;

[0041] The communication bus is used to realize the communication connection between the processor and the memory;

[0042] The processor is used to execute the message sending program stored in the memory to implement the above message sending method.

[0043] The present invention provides a computer-readable storage medium storing one or more programs, which can be executed by one or more processors to implement the above-described message sending method.

[0044] This invention provides a message sending method, apparatus, and storage medium. The method includes: acquiring a target topic from a received control message; acquiring a matching pattern corresponding to the target topic, and determining, based on the matching pattern, a target topic to be matched; querying a preset topic routing table for clients subscribed to the target topic, and identifying the queried clients as target clients; and sending a control message to the target client so that the target client can execute the control operation indicated by the control message. The technical solution provided by this invention, after acquiring the target topic, determines all possible target topics to be matched, and then directly queries the preset topic routing table to obtain clients subscribed to the target topic, thereby sending the control message to the queried clients, improving the accuracy and efficiency of message sending. Attached Figure Description

[0045] Figure 1 This is a flowchart illustrating a message sending method provided in an embodiment of the present invention;

[0046] Figure 2 A subscription tree structure diagram for determining the target topic client in the existing technology;

[0047] Figure 3 A schematic diagram of the structure of a message sending device provided in an embodiment of the present invention. Figure 1 ;

[0048] Figure 4 A schematic diagram of the structure of a message sending device provided in an embodiment of the present invention. Figure 2 . Detailed Implementation

[0049] The technical solutions of the present invention will now be clearly and completely described with reference to the accompanying drawings of the embodiments of the present invention. It is to be understood that the specific embodiments described herein are merely for explaining the relevant application and are not intended to limit the application. Furthermore, it should be noted that, for ease of description, only the parts relevant to the relevant application are shown in the accompanying drawings.

[0050] This invention provides a message sending method, applied to a message sending device. Figure 1 This is a flowchart illustrating a message sending method provided in an embodiment of the present invention. Figure 1 As shown, the main steps include:

[0051] S101. Obtain the target topic of the received control message.

[0052] In embodiments of the present invention, the message sending device can directly obtain the target topic of the received control message.

[0053] It should be noted that, in the embodiments of the present invention, the control message is a message that instructs the client receiving the control message to perform a corresponding control operation, and the target topic is a specific topic on which the publishing client sends the control message. The publishing client can be an electronic device such as a mobile phone or a computer.

[0054] It should be noted that, in the embodiments of the present invention, the target topic includes at least one topic level, and the specific number of topic levels included in the target topic can be set according to actual needs and application scenarios.

[0055] For example, the target topic can be ab / cd / ef, where the forward slash ' / ' is used to separate different topic levels, providing a hierarchical structure for the topic. For instance, the target topic can be Company A / Department B / Employee C, meaning that there is a certain inclusion relationship between each topic level.

[0056] S102. Obtain the matching pattern corresponding to the target topic, and determine the subscription topic to be matched based on the matching pattern.

[0057] In an embodiment of the present invention, the message sending device obtains the matching pattern corresponding to the target topic, and determines the target topic to be matched and subscribed based on the matching pattern.

[0058] It should be noted that, in the embodiments of the present invention, the matching mode in the matching mode corresponding to the target topic obtained by the message sending device can be preset according to the actual scenario and application requirements. When the matching mode obtained by the message sending device is different, the subscription topic to be matched determined based on the corresponding matching mode is also different.

[0059] Specifically, in an embodiment of the present invention, the message sending device determines the target topic to be matched and subscribed based on the matching mode, including: when the matching mode is an exact matching mode, determining the target topic as the target topic to be matched and subscribed.

[0060] It should be noted that, in the embodiments of the present invention, if the matching mode obtained by the message sending device is the exact matching mode, then the target topic is the corresponding subscription topic to be matched. For example, if the target topic is ab / cd / ef, then in the case of the exact matching mode, the subscription topic to be matched determined by the message sending device is ab / cd / ef.

[0061] Specifically, in an embodiment of the present invention, the message sending device determines the target topic to be matched and subscribed based on the matching mode, including: when the matching mode is a single-level wildcard matching mode, obtaining the preset topic corresponding to each topic level from the target topic, and determining the corresponding preset topic and preset single-level wildcard as the corresponding optional topic for each topic level; arranging and combining the optional topics corresponding to different topic levels, and determining each combination obtained by the arrangement and combination as the target topic to be matched and subscribed; wherein, the preset single-level wildcard is a wildcard used to match single-level topics in the target topic.

[0062] It should be noted that, in the embodiments of the present invention, if the matching mode obtained by the message sending device is a single-level wildcard matching mode, then the preset topic corresponding to each topic level is obtained from the target topic. For example, if the target topic is ab / cd / ef, the message sending device obtains the preset topic corresponding to each topic level, namely ab, cd and ef.

[0063] It should be noted that, in the embodiments of the present invention, the message sending device determines the corresponding preset topic and preset single-layer wildcard as the optional topics for each topic level. That is, for the topic level of the preset topic "ab", its optional topics are "ab" or the preset single-layer wildcard "+", for the topic level of the preset topic "cd", its optional topics are "cd" or the preset single-layer wildcard "+", and for the topic level of the preset topic "ef", its optional topics are "ef" or the preset single-layer wildcard "+".

[0064] It should be noted that, in the embodiments of the present invention, the message sending device arranges and combines the optional topics corresponding to different topic levels. When the target topic has three levels, and there are two optional topics in each topic level, eight permutations and combinations will be obtained, namely ab / + / ef, ab / cd / +, + / cd / ef, + / + / ef, + / cd / +, ab / + / +, + / cd / ef, and + / + / +.

[0065] It should be noted that, in the embodiments of the present invention, the message sending device determines each combination obtained by arranging and combining the optional topics corresponding to different topic levels as the subscription topic to be matched. That is, when the target topic is ab / cd / ef and the matching mode is a single-level wildcard matching mode, there are 8 subscription topics to be matched corresponding to the target topic.

[0066] It should be noted that, in the embodiments of the present invention, when the topic level of the target topic is n and the matching mode is a single-level wildcard matching mode, the number of subscription topics to be matched obtained by the message sending device is 2 to the power of n.

[0067] Specifically, in embodiments of the present invention, the message sending device determines the target topic to be matched based on a matching mode, including: when the matching mode is a multi-level wildcard matching mode, obtaining a preset topic corresponding to each topic level from the target topic, and determining the corresponding preset topic and preset single-level wildcard as the corresponding optional topic for each topic level; arranging and combining the optional topics corresponding to different topic levels, and adding a preset multi-level wildcard after each combination; determining each combination with the added preset multi-level wildcard as a full-level subscription topic; determining the corresponding non-full-level subscription topic for each topic level in the target topic based on the preset multi-level wildcard and preset single-level wildcard; and determining the non-full-level subscription topic and the full-level subscription topic as the subscription topics to be matched; wherein, the preset single-level wildcard is a wildcard used to match single-level topics in the target topic, and the preset multi-level wildcard is a wildcard used to match multi-level topics in the target topic.

[0068] It should be noted that, in the embodiments of the present invention, if the matching mode obtained by the message sending device is a multi-level matching mode, then, from the target topic, the preset topics corresponding to each topic level are obtained. For example, if the target topic is ab / cd / ef, the message sending device obtains the preset topics corresponding to each topic level, namely ab, cd, and ef. Then, the preset single-level wildcard '+' is combined with the corresponding preset topics to form optional topics for the corresponding topic level. Finally, the optional topics corresponding to different topic levels are arranged and combined, and a preset multi-level wildcard '#' is added to each combination to obtain the full-level subscription topics of the target topic. For example, when the target topic is ab / cd / ef, the full-level subscription topics obtained by the message sending device are ab / + / ef / #, ab / cd / + / #, + / cd / ef / #, + / + / ef / #, + / cd / + / #, ab / + / + / #, + / cd / ef / #, and + / + / + / #.

[0069] It should be noted that, in the embodiments of the present invention, since the preset multi-level wildcard can be used to match multiple levels of topics in the target topic, when the target topic is ab / cd / ef, the preset multi-level wildcard # in ab / # can match all topics at the topic level corresponding to the preset topics cd and ef in the target topic. At this time, ab / # is a non-full-level subscription topic corresponding to the target topic.

[0070] Specifically, in embodiments of the present invention, the message sending device determines the corresponding non-full-level subscription topic for each topic level in the target topic based on preset multi-level wildcards and preset single-level wildcards, including: for the first topic level corresponding to the preset topic with the largest matching range in the target topic, determining the preset multi-level wildcard as the corresponding non-full-level subscription topic; for each topic level in the target topic that is different from the first topic level, determining the corresponding optional topic combination when the preset multi-level wildcard is used as the corresponding topic based on the preset single-level wildcard; and for each topic level in the target topic that is different from the first topic level, determining the corresponding optional topic combination as the corresponding non-full-level subscription topic.

[0071] It should be noted that, in the embodiments of the present invention, since there is a certain inclusion relationship between each topic level in the topic, the preset topic corresponding to the first topic level has the largest matching range among the preset topics corresponding to each topic level in the topic. The topics corresponding to each topic level are in a progressive relationship. For example, if the preset topic corresponding to the first topic level in the topic is a certain company, the preset topic corresponding to the second topic level can only be a department or employee of that company with a smaller matching range than that company.

[0072] It should be noted that, in the embodiments of the present invention, if the preset multi-level wildcard '#' is used as the target topic, and the topic of the first topic level with the largest matching range is selected, the message sending device directly determines the preset multi-level wildcard as the corresponding non-full-level subscription topic.

[0073] It should be noted that, in the embodiments of the present invention, for each topic level in the target topic that is different from the first topic level, based on a preset single-level wildcard, the corresponding optional topic combinations are determined when a preset multi-level wildcard is used as the corresponding topic. For example, if the target topic is ab / cd / ef, and the preset multi-level wildcard '#' is used as the topic of the topic level corresponding to cd in the target topic, the corresponding optional topic combinations are: ab / # and + / #. At this time, the non-full-level subscription topics corresponding to this topic level are ab / # and + / #.

[0074] Specifically, in embodiments of the present invention, the message sending device, for each topic level in the target topic that is different from the first topic level, determines the corresponding optional topic combinations when using preset multi-level wildcards as the corresponding topics, based on a preset single-level wildcard. This includes: obtaining preset topics corresponding to each topic level in at least one topic level in the target topic that is higher than the second topic level; the second topic level is any topic level in the target topic that is different from the first topic level, and the matching range of the preset topics corresponding to each topic level in the at least one topic level is greater than the matching range of the preset topics corresponding to the second topic level; for each topic level in the at least one topic level, determining the corresponding preset topic and the preset single-level wildcard as the corresponding optional topic; arranging and combining the optional topics corresponding to different topic levels in the at least one topic level, and adding a preset multi-level wildcard after each combination to determine the optional topic combination corresponding to the second topic level.

[0075] It should be noted that, in the embodiments of the present invention, the message sending device obtains a preset topic corresponding to each topic level from the target topic, wherein the topic level is higher than the second topic level. For example, if the target topic is ab / cd / ef, and the preset multi-level wildcard '#' is used as the topic of the topic level corresponding to cd in the target topic, then the message sending device obtains ab, which is higher than the topic level corresponding to cd, and uses ab and the preset single-level wildcard as the optional topic of the topic level corresponding to ab.

[0076] It should be noted that, in the embodiments of the present invention, the message sending device arranges and combines the optional topics of different topic levels in at least one topic level, and adds a preset multi-level wildcard after each combination to determine the optional topic combination corresponding to the second topic level. For example, if the target topic is ab / cd / ef, and the preset multi-level wildcard '#' is the topic of the topic level corresponding to ef in the target topic, the optional topics of the topic level of the preset topic ab are ab or the preset single-level wildcard '+', and the optional topics of the topic level of the preset topic cd are cd or the preset single-level wildcard '+'. After arranging and combining, the result of adding the preset multi-level wildcard is ab / + / #, ab / cd#, + / cd#, and + / + / #, which are the optional topic combinations corresponding to the second topic level.

[0077] It should be noted that, in the embodiments of the present invention, after obtaining the target topic, the message sending device determines all the subscribed topics to be matched with the target topic, and then directly uses them as the basis for querying to determine the corresponding client from the preset topic routing table, thereby improving the efficiency of route matching.

[0078] S103. Query the clients that have subscribed to the topics to be matched from the preset topic routing table, and identify the clients found as the target clients.

[0079] In an embodiment of the present invention, the message sending device queries a preset topic routing table for clients that have subscribed to the topic to be matched, and determines the queried clients as the target clients.

[0080] It should be noted that, in the embodiments of the present invention, the preset topic routing table can be an Elasticsearch (real-time search) database. The message sending device uses the preset topic routing table for data storage, which has strong scalability and strong query capabilities.

[0081] It should be noted that, in the embodiments of the present invention, the preset topic routing table stores the subscribed topics of each client, as well as the service quality level of the client and the subscription time of the topic, as shown in Table 1:

[0082] Table 1

[0083] field name Field Description clientId Client device unique identifier topic Complete topic topicn Multiple topics subscribed to by the client broker The Internet Protocol address of the broker to which the client connects qos QoS rating (Quality of Service) subTimestamp Subscription time for the topic

[0084] Wherein, clientId is the client's identity information, topic is the complete topic subscribed to by the client, topicn is the multiple topics subscribed to by the client, broker is the Internet Protocol address of the server (broker) to which the client connects, qos represents the quality level of service, and subTimestamp is the time of subscription to the topic.

[0085] It should be noted that in the embodiments of the present invention, the relationship between the client and the topic is many-to-many, that is, the same client can subscribe to multiple topics, and the same topic can also be subscribed to by multiple clients. Furthermore, the preset topic routing table lists all the correspondences between the client and the topics it subscribes to. Since the same client cannot concurrently subscribe to or unsubscribe from a topic at the same time, the problem of concurrency safety is solved.

[0086] Figure 2 This provides a subscription tree structure diagram for determining the target topic client in existing technologies. For example... Figure 2 As shown, the subscription tree has a root node, and each arrow represents a token. The path traversed from the root node to its child nodes is defined as a topic. Circles in the diagram represent nodes. A node's content can be empty or contain subscription messages; that is, the subscription messages in a node represent the clients subscribed to that path. For example, if the target topic is ab / cd / ef, the subscription tree finds clients subscribed to this target topic. First, it needs to traverse from the root node through the route "ab / cd / ef" to precisely match client C. Then, based on the predefined multi-level wildcard feature, it can match the multi-level topics within the target topic, traversing through the route "ab / cd / ef". "ab / #" can match clients D and E; finally, based on the preset multi-level wildcards, it can match single-level topics in the target topic. After routing "ab / + / ef", it can match client F, resulting in clients C, D, E, and F corresponding to the target topic. It can be seen that when determining the clients subscribing to the target topic, the subscription tree needs to traverse all paths to find the clients subscribing to the target topic. Furthermore, the subscription messages of the clients in the subscription tree are stored by each node. When updating the subscription information, each storage node needs to be notified, resulting in low data update efficiency and difficulty in resolving the issue of routing information consistency between different nodes.

[0087] It should be noted that, in the embodiments of the present invention, the preset topic routing table is independent of the server (broker). When the message sending device uses the preset topic routing table to store subscription information, if a client subscribes to or unsubscribes from a certain topic, it can directly update the preset topic routing table without notifying the server connected to the client, thus eliminating the need to consider the issue of routing information consistency.

[0088] It should be noted that, in the embodiments of the present invention, the speed at which the message sending device queries the preset topic routing table after determining the topic to be matched for subscription is shown in Table 2:

[0089] Table 2

[0090] Number of topic levels Time required for query 3 10ms 5 10ms 10 30ms 15 600ms 20 28s

[0091] The query results in Table 2 are based on a preset topic routing table with 20 million routing entries. Among these, 100 entries in the preset topic routing table contain preset single-level wildcards and / or preset multi-level wildcards.

[0092] As can be seen from Table 2, when the number of topic levels of the target topic is within 10, the performance of the message sending device in querying the topic to be matched from the preset topic routing table is good. When the number of topic levels of the target topic exceeds 15, the performance of the message sending device in querying the topic to be matched from the preset topic routing table drops sharply. In practical applications, the number of topic levels of a topic is generally less than 5.

[0093] It should be noted that, in the embodiments of the present invention, the preset topic routing table can realize arbitrary mixed queries of clientId, topic, broker, and QoS to meet various query requirements.

[0094] S104. Send the control message to the target client so that the target client can execute the control operation indicated by the control message.

[0095] In an embodiment of the present invention, the message sending device sends a control message to the target client so that the target client can perform the control operation indicated by the control message.

[0096] Specifically, in an embodiment of the present invention, the message sending device sends a control message to the target client by: querying the server Internet Protocol address corresponding to the target client from a preset topic routing table; and forwarding the control message to the target client via the server Internet Protocol address.

[0097] It should be noted that, in the embodiments of the present invention, if communication with the target client is required, the server connected by the target client needs to be used. As can be seen from Table 1, the preset topic routing table stores the Internet Protocol address corresponding to the target server. After the message sending device obtains the Internet Protocol address of the server corresponding to the target client, it sends the message to the target client through the Internet Protocol address of the server.

[0098] This invention provides a message sending method applied to a message sending device. The method includes: acquiring a target topic from a received control message; acquiring a matching pattern corresponding to the target topic, and determining, based on the matching pattern, a subscription topic to be matched corresponding to the target topic; querying a preset topic routing table for clients subscribed to the subscription topics to be matched, and identifying the queried clients as target clients; and sending a control message to the target client so that the target client can execute the control operation indicated by the control message. The method provided by this invention, after acquiring the target topic, determines all possible subscription topics to be matched corresponding to the target topic, and then directly queries the preset topic routing table to obtain clients subscribed to the target topic, thereby sending the control message to the queried clients, improving the accuracy and efficiency of message sending.

[0099] This invention provides a message sending device. Figure 3 A schematic diagram of the structure of a message sending device provided in an embodiment of the present invention. Figure 1 .like Figure 3 As shown, it includes:

[0100] Acquisition module 301 is used to acquire the target topic of the received control message;

[0101] The determining module 302 is used to obtain the matching pattern corresponding to the target topic, and determine the target topic to be matched and subscribed based on the matching pattern;

[0102] The query module 303 is used to query clients that have subscribed to the topic to be matched from the preset topic routing table, and to determine the queried clients as target clients;

[0103] The sending module 304 is used to send the control message to the target client so that the target client can execute the control operation indicated by the control message.

[0104] Optionally, the determining module 302 is specifically used to determine the target topic as the subscription topic to be matched when the matching mode is an exact matching mode.

[0105] Optionally, the determining module 302 is specifically used to, when the matching mode is a single-level wildcard matching mode, obtain a preset topic corresponding to each topic level from the target topic, and for each topic level, determine the corresponding preset topic and preset single-level wildcard as the corresponding optional topic; arrange and combine the optional topics corresponding to different topic levels, and determine each combination obtained by the arrangement and combination as the topic to be matched and subscribed; wherein, the preset single-level wildcard is a wildcard used to match single-level topics in the target topic.

[0106] Optionally, the determining module 302 is specifically configured to, when the matching mode is a multi-level wildcard matching mode, obtain a preset topic corresponding to each topic level from the target topic, and for each topic level, determine the corresponding preset topic and preset single-level wildcard as the corresponding optional topic; arrange and combine the optional topics corresponding to different topic levels, and add a preset multi-level wildcard to each combination obtained by the arrangement and combination; determine each combination with the preset multi-level wildcard as a full-level subscription topic; for each topic level in the target topic, determine the corresponding non-full-level subscription topic based on the preset multi-level wildcard and the preset single-level wildcard; determine the non-full-level subscription topic and the full-level subscription topic as the subscription topic to be matched; wherein, the preset single-level wildcard is a wildcard used to match single-level topics in the target topic, and the preset multi-level wildcard is a wildcard used to match multi-level topics in the target topic.

[0107] Optionally, the determining module 302 is specifically used to: for the first topic level corresponding to the preset topic with the largest matching range in the target topic, determine the preset multi-level wildcard as the corresponding non-full-level subscription topic; for each topic level in the target topic that is different from the first topic level, determine the corresponding optional topic combination when the preset multi-level wildcard is used as the corresponding topic based on the preset single-level wildcard; and for each topic level in the target topic that is different from the first topic level, determine the corresponding optional topic combination as the corresponding non-full-level subscription topic.

[0108] Optionally, the determining module 302 is specifically used to obtain, from the target topic, at least one topic level with a topic level higher than the second topic level, a preset topic corresponding to each topic level; the second topic level is any topic level in the target topic that is different from the first topic level, and the matching range of the preset topics corresponding to each topic level in the at least one topic level is greater than the matching range of the preset topics corresponding to the second topic level; for each topic level in the at least one topic level, the corresponding preset topic and the preset single-layer wildcard are determined as the corresponding optional topic; the optional topics corresponding to different topic levels in the at least one topic level are arranged and combined, and the preset multi-layer wildcard is added after each combination to determine the optional topic combination corresponding to the second topic level.

[0109] Optionally, the sending module 304 is specifically used to query the server Internet Protocol address corresponding to the target client from the preset topic routing table; and forward the control message to the target client through the server Internet Protocol address.

[0110] This invention provides a message sending device. Figure 4 A schematic diagram of the structure of a message sending device provided in an embodiment of the present invention. Figure 2 .like Figure 4 As shown, the message sending device includes: a processor 401, a memory 402, and a communication bus 403;

[0111] The communication bus 403 is used to realize the communication connection between the processor 401 and the memory 402;

[0112] The processor 401 is used to execute the message sending program stored in the memory 402 to implement the above message sending method.

[0113] This invention provides a message sending apparatus that acquires a target topic from a received control message; acquires a matching pattern corresponding to the target topic, and determines, based on the matching pattern, the target topic's corresponding subscribed topics; queries a preset topic routing table for clients subscribed to the subscribed topics, and identifies the queried clients as target clients; and sends a control message to the target client so that the target client can execute the control operation indicated by the control message. The apparatus provided by this invention, after acquiring the target topic, determines all possible subscribed topics corresponding to the target topic, and then directly queries the preset topic routing table to obtain clients subscribed to the target topic, thereby sending the control message to the queried clients, improving the accuracy and efficiency of message sending.

[0114] This invention provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the aforementioned message sending method. The computer-readable storage medium can be volatile memory, such as random-access memory (RAM); or non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); or it can be a device comprising one or any combination of the above-mentioned memories, such as a mobile phone, computer, tablet device, personal digital assistant, etc.

[0115] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.

[0116] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0117] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0118] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0119] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this utility application should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A message sending method, characterized in that, The method includes: Retrieve the target topic of the received control message; Obtain the matching pattern corresponding to the target topic, and based on the matching pattern, determine all subscribed topics that correspond to the target topic; From the preset topic routing table, query the clients that have subscribed to the topic to be matched, and determine the queried clients as the target clients; The control message is sent to the target client so that the target client can execute the control operation indicated by the control message; The method also includes: Obtain a preset topic routing table, which stores all the correspondences between each client and the subscribed topics; If a client has subscribed to or unsubscribed from a topic, the preset topic routing table is updated based on that topic; the preset topic routing table is independent of the server, and the server is connected to the client. The step of determining all subscribed topics to be matched with the target topic based on the matching pattern includes: When the matching mode is a single-level wildcard matching mode, the preset topic corresponding to each topic level is obtained from the target topic, and for each topic level, the corresponding preset topic and preset single-level wildcard are determined as the corresponding optional topic. The optional topics corresponding to different topic levels are arranged and combined, and each combination obtained by the arrangement and combination is determined as the topic to be matched and subscribed.

2. The method according to claim 1, characterized in that, The step of determining the target topic to be matched based on the matching pattern includes: When the matching mode is exact match, the target topic is determined as the topic to be matched and subscribed.

3. The method according to claim 1, characterized in that, The step of determining the target topic to be matched based on the matching pattern includes: When the matching mode is a multi-level wildcard matching mode, the preset topic corresponding to each topic level is obtained from the target topic, and for each topic level, the corresponding preset topic and preset single-level wildcard are determined as the corresponding optional topic. Arrange and combine the optional topics corresponding to different topic levels, and add preset multi-level wildcards after each combination. Each combination with the aforementioned preset multi-level wildcards is identified as a full-level subscription topic; For each topic level in the target topic, the corresponding non-full-level subscription topic is determined based on the preset multi-level wildcard and the preset single-level wildcard; The non-full-level subscription topics and the full-level subscription topics are identified as the subscription topics to be matched; Wherein, the preset single-layer wildcard is a wildcard used to match single-layer topics in the target topic, and the preset multi-layer wildcard is a wildcard used to match multi-layer topics in the target topic.

4. The method according to claim 3, characterized in that, The step of determining the corresponding non-full-level subscription topic for each topic level in the target topic, based on the preset multi-level wildcard and the preset single-level wildcard, includes: For the first topic level corresponding to the preset topic with the largest matching range in the target topic, the preset multi-level wildcard is determined as the corresponding non-full-level subscription topic; For each topic level in the target topic that is different from the first topic level, based on the preset single-level wildcard, determine the corresponding topic options when the preset multi-level wildcard is used as the corresponding topic; For each topic level in the target topic that is different from the first topic level, the corresponding topics can be optionally combined to determine the corresponding non-full-level subscription topic.

5. The method according to claim 4, characterized in that, For each topic level in the target topic that is different from the first topic level, based on the preset single-level wildcard, the possible combinations of topics when using the preset multi-level wildcard as the corresponding topic include: From the target topic, obtain at least one topic level with a topic level higher than the second topic level, and obtain a preset topic corresponding to each topic level; the second topic level is any topic level in the target topic that is different from the first topic level, and the matching range of the preset topics corresponding to each topic level in the at least one topic level is greater than the matching range of the preset topics corresponding to the second topic level; For each topic level in the at least one topic level, the corresponding preset topic and the preset single-level wildcard are determined as the corresponding optional topic; Arrange and combine the optional topics corresponding to different topic levels in the at least one topic level, and add the preset multi-level wildcard after each combination to determine the optional topic combination corresponding to the second topic level.

6. The method according to claim 1, characterized in that, Sending the control message to the target client includes: From the preset topic routing table, query the server Internet Protocol address corresponding to the target client; The control message is forwarded to the target client via the server's Internet Protocol address.

7. A message sending device, characterized in that, The message sending device includes: The acquisition module is used to acquire the target topic of the received control message; The determination module is used to obtain the matching pattern corresponding to the target topic, and based on the matching pattern, determine all subscribed topics to be matched with the target topic; The query module is used to query clients that have subscribed to the topic to be matched from a preset topic routing table, and to identify the queried clients as target clients. The preset topic routing table stores all the correspondences between each client and the subscribed topics. If there is a topic that the client has subscribed to or unsubscribed from, the preset topic routing table is updated based on the topic. The preset topic routing table is independent of the server, and the server is connected to the client. The sending module is used to send the control message to the target client so that the target client can execute the control operation indicated by the control message; The determining module is further configured to, when the matching mode is a single-level wildcard matching mode, obtain a preset topic corresponding to each topic level from the target topic, and determine the corresponding preset topic and preset single-level wildcard as the corresponding optional topic for each topic level; arrange and combine the optional topics corresponding to different topic levels, and determine each combination obtained by the arrangement and combination as the topic to be matched and subscribed.

8. A message sending device, characterized in that, include: Processor, memory, and communication bus; The communication bus is used to realize the communication connection between the processor and the memory; The processor is configured to execute a message sending program stored in the memory to implement the message sending method according to any one of claims 1-6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores one or more programs, which can be executed by one or more processors to implement the message sending method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Message processing system and method based on Internet of Things protocol

    CN110062004A

  • Data transmission method, device and equipment and readable storage medium

    CN113254233A