Method and device for storing message topics

By converting the strings in the MQTT message topic into dictionary tree nodes and storing them, the problem of inefficient storage and management of message topics in the prior art is solved, efficient storage and management are achieved, and storage space is saved.

CN113239307BActive Publication Date: 2025-03-21BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110537088.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-17
Publication Date
2025-03-21
Estimated Expiration
2041-05-17

AI Technical Summary

Technical Problem

The existing MQTT message transmission protocols have problems of inefficiency and waste of storage space when storing and managing message topics, especially when dealing with multiple strings with hierarchical relationships.

Method used

Efficient storage and management are achieved by converting strings in message topics into nodes in dictionary tree according to hierarchical relationships and storing the target dictionary tree.

Benefits of technology

This method can effectively save storage space and improve the efficiency of message topic storage and management, especially when dealing with a large number of message topics with hierarchical relationships.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113239307B_ABST
    Figure CN113239307B_ABST
Patent Text Reader

Abstract

The present disclosure provides a method and device for storing message topics, which relates to the field of computer technology, and in particular to the field of Internet of Things technology. The specific implementation scheme is: obtaining a message topic to be stored, wherein the message topic includes multiple character strings with a hierarchical relationship; according to the hierarchical relationship, converting the character strings in the message topic into nodes in a dictionary tree to obtain a target dictionary tree; and storing the target dictionary tree.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to the field of Internet of Things technology. Background Art

[0002] MQTT (Message Queuing Telemetry Transport) is a "lightweight" communication protocol based on the publish / subscribe model, which is built on the TCP / IP protocol. MQTT is lightweight, simple, open and easy to implement. MQTT is widely used in the Internet of Things, small devices, mobile applications, etc.

[0003] Messages transmitted by MQTT include message topics and payloads. Topic can be used to indicate the type of message, and payload can be used to indicate the content of the message. After a subscriber subscribes to a Topic, he or she will receive the message content (i.e., payload) corresponding to the Topic. Summary of the invention

[0004] The present disclosure provides a method, apparatus, device and storage medium for storing message topics.

[0005] According to one aspect of the present disclosure, a method for storing message topics is provided, comprising: obtaining a message topic to be stored, wherein the message topic includes multiple character strings having a hierarchical relationship; converting the character strings in the message topic into nodes in a dictionary tree according to the hierarchical relationship to obtain a target dictionary tree; and storing the target dictionary tree.

[0006] According to another aspect of the present disclosure, a device for storing message topics is provided, comprising: an acquisition module for acquiring a message topic to be stored, wherein the message topic includes a plurality of character strings having a hierarchical relationship; a conversion module for converting the character strings in the message topic into nodes in a dictionary tree according to the hierarchical relationship to obtain a target dictionary tree; and a storage module for storing the target dictionary tree.

[0007] Another aspect of the present disclosure provides a computing device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method shown in the embodiment of the present disclosure.

[0008] According to another aspect of an embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method shown in the embodiment of the present disclosure.

[0009] According to another aspect of an embodiment of the present disclosure, a computer program product is provided, namely, a computer program. When the computer program is executed by a processor, the method shown in the embodiment of the present disclosure is implemented.

[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0012] Figure 1 A flow diagram schematically illustrates an application scenario of a method for storing message topics according to an embodiment of the present disclosure;

[0013] Figure 2 A flowchart of a method for storing message topics according to an embodiment of the present disclosure is schematically shown;

[0014] Figure 3 A flowchart of a method for converting a character string in a message subject into a node of a dictionary tree according to an embodiment of the present disclosure is schematically shown;

[0015] Figure 4 A flowchart of a method for determining a node identification according to an embodiment of the present disclosure is schematically shown;

[0016] Figure 5 A flowchart of a method for storing message topics according to another embodiment of the present disclosure is schematically shown;

[0017] Figure 6 A schematic diagram of a dictionary tree according to an embodiment of the present disclosure is schematically shown;

[0018] Figure 7 A schematic diagram schematically shows a node of a key / value structure according to an embodiment of the present disclosure;

[0019] Figure 8 A schematic diagram schematically shows a node of a key / value structure according to another embodiment of the present disclosure;

[0020] Fig. 9 A schematic diagram schematically shows a routing relationship from an information topic to a subscriber according to an embodiment of the present disclosure;

[0021] Fig.10 A schematic diagram schematically shows a mapping relationship between subscribers and information topics according to an embodiment of the present disclosure;

[0022] Fig.11 A block diagram schematically shows a device for storing message topics according to an embodiment of the present disclosure; and

[0023] Fig.12 A schematic block diagram of an example electronic device according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION

[0024] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0025] The following will be combined Figure 1 , an application scenario of the method for storing message topics is described in detail.

[0026] Figure 1 A flow chart schematically illustrates an application scenario of a method for storing message topics according to an embodiment of the present disclosure.

[0027] like Figure 1 As shown, the application scenario 100 may include a message publisher (Publisher) 11, a message broker (Broker) 12, and message subscribers (Subscribers) 13, 14, 15.

[0028] The publisher 11 and the subscribers 13, 14, 15 may be clients. The client may be an application or device using the MQTT protocol. It should be noted that the publisher 11 may also be a subscriber at the same time, and the subscribers 13, 14, 15 may also be publishers at the same time.

[0029] The agent 12 may be a server. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.

[0030] According to an embodiment of the present disclosure, the publisher 11 can establish a network connection with the proxy 12, and then publish messages to the proxy 12 that other clients may subscribe to. Subscribers 13, 14, 15 can also establish a network connection with the proxy 12, and obtain the messages published by the publisher 11 through the proxy 12. The proxy 12 can be used to record the message topic (Topic) 21 of the message, and the subscriber information 22 corresponding to each message topic 21. When the publisher 11 publishes a new message, the proxy 12 can determine the subscribers 13, 14, 15 who have subscribed to the message based on the subscriber information 22 corresponding to the message topic 21 of the message. Then send the message to the subscribers 13, 14, 15.

[0031] It should be noted that the method for storing message topics provided by the present disclosure can be executed by the agent 12. Accordingly, the device for storing message topics provided by the present disclosure can be set in the agent 12. The method for storing message topics provided by the present disclosure can also be executed by a server or server cluster that is different from the agent 12 and can communicate with the agent 12. Accordingly, the device for storing message topics provided by the present disclosure can also be set in a server or server cluster that is different from the agent 12 and can communicate with the agent 12.

[0032] It should be understood that Figure 1 The number of publishers, agents, and subscribers in the example is only illustrative. Depending on the implementation requirements, there can be any number of publishers, agents, and subscribers.

[0033] The following will be combined Figure 2 , a method for storing message topics is described in detail.

[0034] Figure 2 The flowchart of the method for storing message topics according to an embodiment of the present disclosure is schematically shown.

[0035] like Figure 2 As shown, the method 200 for storing message topics may include operations S210 to S230.

[0036] In operation S210, a message subject to be stored is obtained.

[0037] According to an embodiment of the present disclosure, a message subject may be used to indicate the type of a message transmitted between multiple devices, and the message subject may include multiple character strings having a hierarchical relationship. Exemplarily, in this embodiment, the character string may include a product identifier, a device name, and the like.

[0038] Then, in operation S220, the character string in the message subject is converted into a node in a dictionary tree according to the hierarchical relationship to obtain a target dictionary tree.

[0039] According to an embodiment of the present disclosure, a trie is a tree data structure, and a message subject can be converted into a trie for storage. During the conversion, a corresponding node in the trie can be configured according to each string in the message subject, and a parent-child relationship between nodes can be configured according to a hierarchical relationship between strings.

[0040] In operation S230, the target dictionary tree is stored.

[0041] According to an embodiment of the present disclosure, by converting message subjects into a dictionary tree according to the hierarchy and using the dictionary tree to save the message subjects, storage space can be saved.

[0042] The following will be combined Figure 3 , a method for converting a string in a message subject into a node of a dictionary tree according to a hierarchical relationship is described in detail.

[0043] Figure 3 The flowchart of the method for converting a character string in a message subject into a node of a dictionary tree according to an embodiment of the present disclosure is schematically shown.

[0044] like Figure 3 As shown, the method 330 of converting a character string in a message subject into a node of a dictionary tree may include operations S331 to S334, for example.

[0045] In operation S331 , a node corresponding to each character string is determined to obtain a plurality of nodes.

[0046] According to an embodiment of the present disclosure, each string corresponds to a node in a dictionary tree. In this embodiment, if the highest-level strings of different message topics are the same, these highest-level strings can be converted to root nodes in the same dictionary tree. In addition, if for different message topics, the strings in multiple levels starting from the highest level are the same, these same strings can be converted to the same node in the same dictionary tree.

[0047] For example, for the two message topics: forex / stock / nyse and forex / stock / #, their highest level is forex and the second highest level is stock. Therefore, the forex in the two message topics can be converted to the same root node in the same dictionary tree, and the stock in the two message topics can be converted to the same child node of the root node.

[0048] In operation S332 , a parent-child relationship between a plurality of nodes is determined according to a hierarchical relationship between a plurality of character strings.

[0049] According to an embodiment of the present disclosure, nodes can be generated in order from high to low levels. For example, the string of the first level can be converted into a root node, the string of the second level can be converted into a child node of the root node, and then the string of the third level can be converted into a child node of the child node, and so on, until the string of the last level (i.e., the lowest level) is converted into a corresponding node (i.e., a leaf node).

[0050] In operation S333 , a node identifier of each of the plurality of nodes is determined, and a key value of the node is determined according to the node identifier.

[0051] According to an embodiment of the present disclosure, a node identifier can be used to identify each node, and the node identifiers of different nodes are different. The key value of the node can be determined based on the node identifier of the node and the number of child nodes of the node. Exemplarily, in this embodiment, the node identifier and the number of child nodes identifier used to represent the number of child nodes can be spliced ​​together to obtain the key value of the node. Among them, the node identifier and the number of child nodes identifier can be spliced ​​in any way. Exemplarily, in this embodiment, the node identifier can be used as the head and the number of child nodes identifier can be spliced ​​together as the tail to obtain the key value of the node.

[0052] For example, if the node identifier of a node is 0x0001 and the number of child nodes of the node is 2, the child node identifier can be determined to be 02, and then the node identifier 0x0001 is used as the head and the number of child nodes identifier 02 is used as the tail to concatenate together to obtain the key value of the node as <0x0001>02, where "<" and ">" are separators.

[0053] According to an embodiment of the present disclosure, a node identifier may be configured as a string of fixed length, thereby reducing space complexity.

[0054] In operation S334, a key name of the node is determined according to the character string corresponding to each node.

[0055] According to an embodiment of the present disclosure, for a node that is a root node, the key name of the node can be determined based on a fixed identifier and a string corresponding to the node. The fixed identifier can be set arbitrarily while ensuring that it does not overlap with the node identifiers of other nodes. According to an embodiment of the present disclosure, for a node that is not a root node, the key name of the node can be determined based on the node identifier of the node's parent node and a string corresponding to the node. Through the above-mentioned key name setting method, the key name of the node contains the information of the node's parent node, so that the hierarchical relationship between the nodes can be determined based on the key name of the node.

[0056] For example, in this embodiment, for a root node, a fixed identifier and a string corresponding to the root node may be concatenated to obtain the key name of the root node. For a node that is not a root node, a node identifier of the parent node of the node and a string corresponding to the node may be concatenated to obtain the key name of the node. Any concatenation method may be used.

[0057] For example, in this embodiment, for a root node, a fixed identifier can be used as a header, and a string corresponding to the root node can be concatenated as a tail to obtain the key name of the root node. For a node that is not a root node, the node identifier of the parent node of the node can be used as a header, and a string corresponding to the node can be concatenated as a tail to obtain the key name of the node.

[0058] For example, the fixed identifier of the root node is 0x0000, and the string corresponding to the root node is forex. Then the fixed identifier 0x0000 can be used as the head, and the string forex corresponding to the root node can be used as the tail to concatenate together to obtain the key name of the root node <0x0000>forex, where "<" and ">" are separators.

[0059] For another example, the node identifier of the parent node is 0x000A, and the string corresponding to a child node of the parent node is stock. Then, the node identifier 0x000A can be used as the head, and the string stock corresponding to the child node can be used as the tail to concatenate together to obtain the key name of the child node as <0x000A>stock.

[0060] The following will be combined Figure 4 , a detailed description is given for determining the node identity.

[0061] Figure 4 The flowchart of the method for determining a node identification according to an embodiment of the present disclosure is schematically shown.

[0062] like Figure 4 As shown, the method for determining a node identifier may include, for example, operations S410 to S420.

[0063] In operation S410, for each node, a process identifier, a leaf node identifier, a time identifier, and a sequence value corresponding to the node are determined.

[0064] According to an embodiment of the present disclosure, a leaf node identifier may be determined based on whether the node is a leaf node. Exemplarily, in this embodiment, a leaf node identifier corresponding to a leaf node may be configured as 1, and a leaf node identifier corresponding to a non-leaf node may be configured as 0.

[0065] According to an embodiment of the present disclosure, a time identifier may be determined according to a reference time and a system timer value, wherein the reference time may be a time for acquiring a message subject to be stored.

[0066] For example, in this embodiment, the current wall clock time (WallClock) T may be recorded when the process for operating the dictionary tree is started. w As the reference time, the system's nanosecond time (nanoSecond) T ns As the system timer value, where the wall clock time is in milliseconds and the nanosecond value time is in nanoseconds. Then get the current nanosecond value time T each time the operation that generates the time stamp is triggered ns ′, the final time stamp timestamp = T w +Floor((T ns ′-T ns ) / 1000000), where Floor represents a floating-point type conversion operation.

[0067] According to an embodiment of the present disclosure, the process identifier can be, for example, a global identifier for each process used to operate the dictionary tree. The system timestamp when the process used to operate the dictionary tree is started can be obtained, and the process identifier can be determined based on the timestamp. Exemplarily, in this embodiment, the timestamp at startup can be obtained through the system's UnixTimeStamp parameter, and the timestamp is accurate to seconds. The lower 15 bits of the timestamp are then used as the process identifier. The process identifier generated in this way is accurate to seconds and can be non-repeated within about 9 hours.

[0068] According to an embodiment of the present disclosure, a sequence value corresponding to a node can be obtained according to the order in which the node is generated in a plurality of nodes. Exemplarily, in this embodiment, the sequence value is a value between 0 and 1023, the initial value of the sequence value is 0, and each time a new sequence value is generated, the last obtained sequence value is added by one and modulo 1024 to obtain a new sequence value.

[0069] In operation S420, a node identifier of the node is determined according to the process identifier, the leaf node identifier, the time identifier, and the sequence value.

[0070] According to an embodiment of the present disclosure, a process identifier, a leaf node identifier, a time identifier and a sequence value can be spliced ​​together to obtain a node identifier. Among them, the process identifier, the leaf node identifier, the time identifier and the sequence value can be spliced ​​in any way. Exemplarily, this embodiment uses the leaf node identifier as the head, and splices the time identifier, the process identifier and the sequence value in the order of the time identifier, the process identifier and the sequence value behind the leaf identifier to obtain a node identifier. For example, if the leaf node identifier of the node is 0, the time identifier is 10, the process identifier is 20, and the sequence value is 30, then the time identifier 10, the process identifier 20 and the sequence value 30 can be spliced ​​in turn behind the leaf identifier 0 to obtain a node identifier of 0102030.

[0071] Figure 5 The flowchart of a method for storing message topics according to another embodiment of the present disclosure is schematically shown.

[0072] like Figure 5 As shown, the method 500 for storing message topics may include, for example, operations S510 to S560.

[0073] In operation S510, a message subject to be stored is obtained.

[0074] According to an embodiment of the present disclosure, operation S510 may refer to the operation of obtaining the message subject to be stored as shown above, and will not be described in detail here.

[0075] In operation S520, the character string in the message subject is converted into a node in a dictionary tree according to the hierarchical relationship to obtain a target dictionary tree.

[0076] According to an embodiment of the present disclosure, operation S520 may refer to the operation of obtaining the target dictionary tree shown above, which will not be repeated here.

[0077] In operation S530, the target trie is stored.

[0078] According to an embodiment of the present disclosure, operation S530 may refer to the operation of storing the target dictionary tree shown above, which will not be described in detail here.

[0079] In operation S540, in response to receiving subscriber information for a message subject, a routing relationship between the message subject and the subscriber information is acquired.

[0080] According to an embodiment of the present disclosure, the subscriber information may include, for example, identification information of a subscriber who subscribes to the message topic. The routing relationship between the message topic and the subscriber information may be used to indicate which subscribers have subscribed to the message topic.

[0081] In operation S550, a target key-value pair is generated according to a routing relationship between the message subject and the subscriber information.

[0082] According to an embodiment of the present disclosure, a target key-value pair includes a target key name and a target key value, the target key name may include a node identifier of a node corresponding to a string at the lowest level in a message subject, and the target key value may include subscriber information.

[0083] In operation S560, the target key-value pair is stored.

[0084] According to an embodiment of the present disclosure, when storing the routing relationship between a message subject and subscriber information, by using the node identifier of the node corresponding to the lowest level in the message subject as the key name, the length of the key name can be reduced, thereby saving storage space, compared to using the message subject itself as the key name.

[0085] Reference below Figure 6 to Figure 10 , the method for storing message topics is further described in conjunction with a specific embodiment. Those skilled in the art can understand that the following exemplary embodiments are only used to understand the present disclosure, and the present disclosure is not limited thereto.

[0086] Exemplarily, in this embodiment, the message topics to be stored (hereinafter referred to as Topics) include the following:

[0087] forex / stock / nyse

[0088] forex / stock / #

[0089] forex / index

[0090] forex / + / nyse

[0091] forex / +

[0092] Each Topic includes multiple strings, and the delimiter " / " is used to separate the strings to indicate the hierarchical relationship between the strings. For example, forex / stock / nyse includes three strings: forex, stock, and nyse, where forex corresponds to the first level (the highest level), stock corresponds to the second level (the second lowest level), and nyse corresponds to the third level (the lowest level).

[0093] Figure 6 A schematic diagram of a dictionary tree according to an embodiment of the present disclosure is schematically shown.

[0094] like Figure 6As shown in the figure, for each Topic, the split is performed according to the level, and the split strings are converted into nodes of the dictionary tree, where the first level is converted into the root node, the last level is converted into the leaf node, and the other levels are converted into nodes between the root node and the leaf node according to the hierarchical relationship. After the conversion, the path from the root node to each leaf node represents a complete Topic. Figure 6 In the example, the Topic in the above example is converted into a dictionary tree, the first-level forex is converted into the root node 611, the second-level stock, index and "+" are converted into nodes 621, 622 and 623 between the root node and the leaf node respectively, and the lowest-level nyse, "#" and nyse are converted into leaf nodes 631, 632 and 633 respectively.

[0095] According to an embodiment of the present disclosure, when Trie is used to store Topics, if the strings of the highest level of different Topics are the same, these strings of the highest level can be converted into the root nodes of the same Trie. In addition, if the strings of multiple levels starting from the highest level are the same for different Topics, these same strings can be converted into the same node point in the same Trie, thereby saving space.

[0096] According to the embodiment of the present disclosure, after the Topic is saved as a Trie, the Trie is temporarily stored in the memory, so that the Trie can be constructed in the memory and various operations of adding, deleting, modifying and checking can be performed. However, the memory of a single machine always has an upper limit. In order to save more Topic information, the Trie can also be saved in the database.

[0097] According to the embodiment of the present disclosure, each node in the Trie has a value, and the value of the value is a string of the corresponding level of the Topic. In addition, except for the root node, each node has a parent node. Therefore, the nodes in the Trie can be converted into a key / value (key name / key value) structure, where the key is the path from the parent node to this node, and the key of the root node can be its corresponding string. The value is the list of child nodes of this node. Based on this, Figure 7 The schematic diagram schematically shows a node of a key / value structure according to an embodiment of the present disclosure. Figure 7In the example, the key 711A of the root node 611 is forex, and the value 711B of the root node 611 is a list of the child nodes 621, 622, and 623 of the node 611.<stock,index,+> In addition, the key 721A of node 621 is the path forex / stock from the root node 611 to the node 621, and the value 721B of node 621 is the list of child nodes 631 and 632 of node 621.<nyse,#> . The key 731A of leaf node 631 is the path forex / stock / nyse from root node 611 to leaf node 631, and the value 731B of leaf node 631 is an empty list <>. Similarly, the key 732A of node 632 is the list forex / stock / #, and the value 732B of node 632 is an empty list <>. The key 722A of node 622 is the list forex / index, and the value 722B of node 622 is an empty list <>. The key 723A of node 623 is the list forex / +, and the value 723B of node 623 is the list <nyse>The key 733A of the node 633 is the list forex / + / nyse, and the value 733B of the node 633 is the empty list <>.

[0098] like Figure 7 As shown in the figure, the space occupied by the key of each node is related to the length of the string at each level in the Topic. When the Topic is in the form of " / a…a / … / aaa / aa / a", that is, the length of the string at each level decreases from left to right, the space complexity is O(M*N 2 ), where M is the maximum substring length and N is the particle time. It can be seen that the space overhead is relatively large.

[0099] According to another embodiment of the present disclosure, in order to reduce space complexity, a unique fixed-length node identifier can be generated for each node as a prefix of the node key. Assuming that the length of the node identifier is 64 bits, the overall space overhead is 16*(N-1) bytes, and the space complexity is O(N), which reduces the space overhead and space complexity.

[0100] Based on this, Figure 8 A schematic diagram schematically shows a node of a key / value structure according to another embodiment of the present disclosure.

[0101] like Figure 8 As shown, the key corresponding to each level is obtained by concatenating the string of this level with a prefix of a fixed length, and the corresponding value is the node identifier of this level with a fixed length. By way of example, in this embodiment, the node identifier has a total of 64 bits, and the components from high to low are: 1-bit leaf node identifier, 38-bit timestamp, 15-bit global process identifier globalprocess id, and 10-bit sequence value sequence. Among them, the highest-order leaf node identifier is used to identify the leaf node. If this bit is 1, it means that the node is a leaf node, and if this bit is 0, it means that the node is not a leaf node.

[0102] timestamp is a locally generated, monotonically increasing time stamp accurate to milliseconds, which can be used for 8.7 years without repeating. In order to ensure the monotonically increasing nature of the timestamp part, it can be used to record the current WallClock parameter T when the process operating the dictionary tree is started. w As the reference time, the system's nanoSecond parameter T ns As the system timer value, where the WallClock parameter is in milliseconds and the nanoSecond parameter is in nanoseconds. Then get the current nanosecond value time T each time the operation generating the time mark is triggered ns ′, and finally get the time stamp timestamp = T w +Floor((T ns ′-T ns ) / 1000000), where Floor represents a floating point type conversion operation. The global process id is the global identifier of each process that wants to operate the Trie. The lower 15 bits of the Unix TimeStamp parameter can be obtained as the global process id. In this way, a unique id with second precision can be generated within about 9 hours. Exemplarily, in this embodiment, only one process is started in the same second to ensure that the global identifier of the process is unique. Sequence is a value between 0 and 1023. The initial value of sequence is 0. Each time a new sequence is generated, the last sequence value is added by one and modulo 1024 to obtain a new sequence value.

[0103] After using the above algorithm to generate a fixed-length node identifier for each node, the node identifier can be used as the node pointer of the node. Based on this, for each node, the node pointer of the parent node can be used as a prefix, followed by the string of this node to get the key of the node. Since the root node has no parent node, the root node can use a fixed value, such as 0x0000 as a prefix. The value of the node is a 12-byte data, the first 8 bytes are the node pointer of this node, and the next four bytes are the number of child nodes of this node. By converting a Trie node into a key / value structure through the above method, any KV (key / value) database can be used for storage.

[0104] For example, in Figure 8 In the example, the string forex corresponds to the root node 811. For example, in this embodiment, the fixed prefix of the root node 811 is 0x0000, where 0x represents hexadecimal. Therefore, it can be determined that the key 811A of the root node 811 is <0x0000>forex, where "<" and ">" are separators. In addition, the node identifier of the root node 811 is 0x000A, and the root node 811 has 3 child nodes, so the value 811B of the root node 811 is <0x000A>03.

[0105] The string "+" corresponds to node 823, and the parent node of node 823 is root node 811. Therefore, the node identifier 0x000A of root node 811 can be concatenated with the string "+" of node 823, and the key 823A of node 823 is <0x000A>+. Then the node identifier of node 823 is 0x0003, and node 823 has one child node, so the value 823B of node 823 is <0x0003>01.

[0106] The string nyse corresponds to leaf node 833, and the parent node of leaf node 833 is node 823 corresponding to the string "+". Therefore, the node identifier 0x0003 of node 823 can be concatenated with the string nyse of leaf node 833, and the key 833A of leaf node 833 is <0x0003>nyse. Then the node identifier of leaf node 833 is 0x0006, and leaf node 833 has no child nodes, so the value 833B of leaf node 833 is <0x0006>00.

[0107] For example, Table 1 schematically shows a schematic diagram of the routing relationship between message topics and subscribers according to this embodiment, wherein inbox1(0), inbox2(0), inbox2(1), inbox3(0), inbox4(0) and inbox5(0) represent different subscriber information.

[0108] Message Subject Subscribers forex / stock / nyse inbox1(0), inbox2(1) forex / stock / # inbox2(0) forex / index inbox3(0), inbox4(0) forex / + / nyse inbox4(0) forex / + inbox5(0)

[0109] Table 1

[0110] Based on this, Fig. 9 The schematic diagram schematically shows the routing relationship from information subject to subscriber according to the embodiment of the present disclosure. Fig. 9 As shown in the figure, when saving the routing relationship from message subject to subscriber information, for each message subject, the node pointer of the lowest level of the message subject in the Trie (i.e. TriNodePointer) can be used as the key, and all the subscribers corresponding to the message subject (i.e. Subinfo) can be used as the value to generate a key-value pair and store it in the Map. Therefore, when a message subject needs to be matched, the node pointer of the message subject can be found according to the Trie structure first, and then the corresponding subscriber can be found according to the node pointer.

[0111] For example, in Fig. 9 In the example, the lowest level of forex / stock / nyse is the node pointer in the Trie corresponding to the node identifier 0x0004 of the string nyse. The subscribers of forex / stock / nyse include inbox1(0) and inbox2(1). Therefore, <0x0004> can be used as the key.<inbox1(0),inbox2(1)> As value, a key-value pair is generated to record the routing relationship from forex / stock / nyse to subscriber information. Similarly, key-value pairs for recording other routing relationships in Table 1 can be generated respectively.

[0112] also, Fig.10 The following is a schematic diagram showing a mapping relationship between subscribers and information topics according to another embodiment of the present disclosure. Fig.10 As shown, another Map can be used to save the mapping from subscribers to information topics, so as to facilitate finding all information topics subscribed by the subscriber.

[0113] exist Fig.10 In the example, subscribers include inbox1, inbox2, inbox3, inbox4, and inbox5. For each subscriber, multiple key-value pairs can be generated with the subscriber as the key and the message topic (TopicFilterinfo) subscribed by the subscriber as the value to record the mapping relationship between the subscriber and the information topic. For example, the topics subscribed by subscriber inbox1 include forex / stock / nyse. Therefore, the key corresponding to the subscriber is inbox1, and the corresponding value is <"forex / stock / nyse">.

[0114] Fig.11 A block diagram of a device for storing message topics according to an embodiment of the present disclosure is schematically shown.

[0115] like Fig.11 As shown, the device 1100 for storing message topics includes an acquisition module 1110 , a conversion module 1120 and a storage module 1130 .

[0116] The acquisition module 1110 may be used to acquire a message subject to be stored, wherein the message subject includes a plurality of character strings having a hierarchical relationship.

[0117] The conversion module 1120 can be used to convert the character string in the message subject into a node in the dictionary tree according to the hierarchical relationship to obtain a target dictionary tree.

[0118] The storage module 1130 may be used to store the target dictionary tree.

[0119] It should be noted that the acquisition, storage and application of information involved in the technical solution of the present disclosure are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0120] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0121] Fig.12 A schematic block diagram of an example electronic device 1200 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0122] like Fig.12 As shown, the device 1200 includes a computing unit 1201, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1202 or a computer program loaded from a storage unit 1208 into a random access memory (RAM) 1203. In the RAM 1203, various programs and data required for the operation of the device 1200 can also be stored. The computing unit 1201, the ROM 1202, and the RAM 1203 are connected to each other via a bus 1204. An input / output (I / O) interface 1205 is also connected to the bus 1204.

[0123] A number of components in the device 1200 are connected to the I / O interface 1205, including: an input unit 1206, such as a keyboard, a mouse, etc.; an output unit 1207, such as various types of displays, speakers, etc.; a storage unit 1208, such as a disk, an optical disk, etc.; and a communication unit 1209, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1209 allows the device 1200 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0124] The computing unit 1201 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1201 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1201 performs the various methods and processes described above, such as a method for storing a message subject. For example, in some embodiments, the method for storing a message subject may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 1208. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1200 via the ROM 1202 and / or the communication unit 1209. When the computer program is loaded into the RAM 1203 and executed by the computing unit 1201, one or more steps of the method for storing a message subject described above may be performed. Alternatively, in other embodiments, the computing unit 1201 may be configured to execute the method for storing message topics in any other appropriate manner (eg, by means of firmware).

[0125] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0126] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0127] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0128] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0129] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0130] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.

[0131] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0132] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.< / nyse>

Claims

1. A method for storing a message topic, comprising: Acquire a message subject to be stored, wherein the message subject includes a plurality of character strings having a hierarchical relationship; According to the hierarchical relationship, convert the character string in the message subject into a node in a dictionary tree to obtain a target dictionary tree; and Storing the target dictionary tree; Wherein, converting the character string in the message subject into a node of a dictionary tree according to the hierarchical relationship includes: generating a key name and a key value of each node in the dictionary tree, including: Configure a fixed-length node identifier for each node; For each node, determine the key value of the node according to the node identifier of the node and the number of child nodes under the node; For each node except the root node, concatenate the node identifier of the parent node of the node and the string corresponding to the node to obtain the key name of the node; The key name of the root node is obtained by concatenating a fixed identifier and a character string corresponding to the root node; The method further comprises: In response to receiving subscriber information for the message subject, acquiring a routing relationship between the message subject and the subscriber information; Generate a target key name according to the node identifier of the node corresponding to the lowest-level character string in the message subject, and generate a target key value according to the subscriber information corresponding to the message subject in the routing relationship; Combining the target key name and the target key value into a target key-value pair, wherein the target key-value pair represents a routing relationship between the message subject and the subscriber information; and The target key-value pair is stored.

2. The method according to claim 1, wherein: The node includes a key name and a key value corresponding to each other; the node of converting the string in the message subject into a dictionary tree according to the hierarchical relationship also includes: Determine the node corresponding to each of the character strings to obtain multiple nodes; The parent-child relationship between the multiple nodes is determined according to the hierarchical relationship between the multiple character strings.

3. The method according to claim 2, wherein: Determining the key value of the node according to the node identifier includes: The key value of the node is determined according to the node identifier of the node and the number of child nodes of the node.

4. The method according to any one of claims 2 to 3, wherein: The determining of the node identifier of each node includes: For each of the nodes, determining a process identifier, a leaf node identifier, a time identifier, and a sequence value corresponding to the node; and The node identifier of the node is determined according to the process identifier, the leaf node identifier, the time identifier and the sequence value.

5. The method according to claim 4, wherein: The determining of the leaf node identifier corresponding to the node includes: The leaf node identifier is determined according to whether the node is a leaf node.

6. The method according to claim 4, wherein: The determining of a time identifier corresponding to the node includes: The time identifier is determined according to a reference time and a system timer value, wherein the reference time is the time of obtaining the message subject to be stored.

7. The method according to claim 4, wherein: The determining of the sequence value corresponding to the node includes: According to the order in which the node is generated among a plurality of nodes, a sequence value corresponding to the node is obtained.

8. A device for storing message topics, comprising: An acquisition module, used to acquire a message subject to be stored, wherein the message subject includes a plurality of character strings having a hierarchical relationship; A conversion module, used for converting the character string in the message subject into a node in a dictionary tree according to the hierarchical relationship to obtain a target dictionary tree; and A first storage module, used for storing the target dictionary tree; The conversion module is further used to generate a key name and a key value for each node in the dictionary tree, specifically to configure a node identifier of a fixed length for each node; for each node, the key value of the node is determined according to the node identifier of the node and the number of child nodes under the node; for each node except the root node, the node identifier of the parent node of the node and the character string corresponding to the node are concatenated to obtain the key name of the node; wherein the key name of the root node is obtained by concatenating the fixed identifier and the character string corresponding to the root node; The device also includes: a second storage module, which is used to obtain the routing relationship between the message subject and the subscriber information in response to receiving the subscriber information for the message subject; generate a target key name according to the node identifier of the node corresponding to the lowest-level character string in the message subject, and generate a target key value according to the subscriber information corresponding to the message subject in the routing relationship; combine the target key name and the target key value into a target key-value pair, wherein the target key-value pair represents the routing relationship between the message subject and the subscriber information; and store the target key-value pair.

9. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.

11. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Rapid matching method and system for MQTT theme in Internet of Things gateway

    CN111651476A

  • Method and device for querying child nodes under catalogue, electronic equipment and medium

    CN111966633A