Data consumption method, device and electronic device of distributed cluster
By allocating topic information to each electronic device in the TD server of the theme distributor, making its client identification information different from the subscription topic information, the problem of low message consumption capacity and repeated consumption on the MQTT server is solved, and fast consumption and expansion are achieved.
Patent Information
- Application Number
- CN202211338510.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-28
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2042-10-28
AI Technical Summary
In the prior art, the message consumption capacity of the MQTT server is low, resulting in slower efficiency in subscribing to all topics to receive messages, and the problem of repeated consumption may occur when expanding multiple processes.
By receiving the topic list and client registration information sent by the target electronic device in the topic distributor TD server, the topic information in the topic list is allocated to each electronic device in the cluster, so that the client identification information of each electronic device is different from the subscribed topic information, thereby avoiding repeated consumption and improving consumption capacity through dynamic expansion.
The rapid consumption of MQTT server messages has been realized, the problem of repeated consumption is avoided, and the message consumption capacity has been improved through electronic equipment expansion.
Smart Images

Figure CN115776519B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data consumption method, device and electronic equipment for a distributed cluster. Background Art
[0002] As the volume of business gradually increases, the amount of messages stored in the MQTT (Message Queuing Telemetry Transport) server is increasing, resulting in a slow efficiency for the MQTT server to subscribe to all topics and receive messages. Therefore, it is necessary to quickly consume the messages in the MQTT server. If the MQTT server has only a single process, the consumption rate is slow, and it is necessary to expand multiple processes and specify corresponding client identification information to enhance the consumption capacity of the MQTT server. When specifying client identification information for multiple processes, if different client identification information is specified for multiple processes, each process may consume based on the same list of topics, which may result in repeated consumption and fail to enhance consumption capacity. Summary of the invention
[0003] The present invention provides a distributed cluster data consumption method, device and electronic device to solve the defect of low consumption capacity in the prior art, enhance the consumption capacity by allocating subject information to each electronic device, and realize dynamic expansion and contraction of electronic devices.
[0004] The present invention provides a distributed cluster data consumption method, which is applied to a topic distributor TD server, comprising:
[0005] Receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster;
[0006] When the topic list and the client registration information exist in the first shared cache of the TD server, the topic information in the topic list is distributed to each electronic device in the cluster to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information distributed to each of the electronic devices is different.
[0007] According to the data consumption method of the distributed cluster provided by the present invention, the distributing the subject information in the subject list to each electronic device in the cluster includes:
[0008] The topic information in the topic list is evenly distributed to each electronic device in the cluster.
[0009] According to the distributed cluster data consumption method provided by the present invention, the client registration information includes client identification information and host information;
[0010] The method further comprises:
[0011] Based on the client identification information and the host information, determining second topic information that each of the electronic devices needs to subscribe to;
[0012] Based on the second theme information corresponding to each of the electronic devices, the first theme information allocated to each of the electronic devices is updated.
[0013] According to the distributed cluster data consumption method provided by the present invention, the method further includes:
[0014] Regularly detecting the communication information of each of the registered electronic devices;
[0015] Determine the electronic device that has not updated the communication information within a preset period of time, and delete the client registration information of the electronic device;
[0016] The topic information in the topic list is redistributed to each of the surviving electronic devices.
[0017] According to the distributed cluster data consumption method provided by the present invention, the method further includes:
[0018] After deleting the client registration information of the electronic device, the first subject information corresponding to the electronic device is redistributed to each surviving electronic device.
[0019] The present invention also provides a distributed cluster data consumption method, which is applied to a target electronic device, comprising:
[0020] Acquire a topic list from the second shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0021] Send the topic list and client registration information to the topic distributor TD server through the client, and lock the shared cache;
[0022] receiving first topic information sent by the TD server, where the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the second shared cache;
[0023] A subscription request is generated based on the first topic information, and data from the MQTT server is consumed based on the subscription request.
[0024] According to the distributed cluster data consumption method provided by the present invention, the method further includes:
[0025] Regularly updating the first subject information;
[0026] Receiving second topic information sent by the TD server, where the second topic information is redistributed by the TD server based on the registration information of each client;
[0027] The first subject information is compared with the second subject information, and based on the comparison result, third subject information corresponding to each of the electronic devices is determined, and the third subject information is used to generate a subscription request or cancel a subscription.
[0028] According to the distributed cluster data consumption method provided by the present invention, the determining, based on the comparison result, the third subject information corresponding to each of the electronic devices includes:
[0029] If the comparison result includes: first difference topic information that exists in the second topic information and does not exist in the first topic information, the first difference topic information is determined as the third topic information, so that the electronic device subscribes to the third topic information from the MQTT server;
[0030] If the comparison result includes: second difference subject information that does not exist in the second subject information but exists in the first subject information, the second difference subject information is determined as the third subject information, so that the electronic device cancels the subscription to the third subject information based on the subscription to the first subject information.
[0031] The present invention also provides a distributed cluster data consumption device, which is applied to a topic distributor TD server, comprising:
[0032] A first receiving module, configured to receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster;
[0033] An allocation module is used to allocate the topic information in the topic list to each electronic device in the cluster when the topic list and the client registration information exist in the first shared cache of the TD server, so as to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information allocated to each of the electronic devices is different.
[0034] The present invention also provides a distributed cluster data consumption device, which is applied to a target electronic device, comprising:
[0035] An acquisition module, configured to acquire a topic list from the second shared cache, wherein the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0036] A sending module, used for sending the topic list and client registration information to the topic distributor TD server through the client, and locking the shared cache;
[0037] A second receiving module is used to receive first topic information sent by the TD server, where the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the second shared cache;
[0038] The subscription module is used to generate a subscription request based on the first topic information and consume data from the MQTT server based on the subscription request.
[0039] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the distributed cluster data consumption method described in any one of the above methods is implemented.
[0040] The data consumption method, device and electronic device of a distributed cluster provided by the present invention, by adding a TD server, and when receiving a topic list and client registration information sent by an electronic device, all topic information in the topic list is distributed to each electronic device, so that the client identification information of each electronic device is different and the subscribed first topic information is different, thereby avoiding repeated consumption of messages from the MQTT server, and improving the consumption capacity of MQTT server messages by expanding the capacity of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 This is one of the flow charts of the distributed cluster data consumption method provided by the present invention;
[0043] Figure 2 This is the second flow chart of the distributed cluster data consumption method provided by the present invention;
[0044] Figure 3 This is the third flow chart of the distributed cluster data consumption method provided by the present invention;
[0045] Figure 4 This is the fourth flow chart of the distributed cluster data consumption method provided by the present invention;
[0046] Figure 5 This is the fifth flow chart of the distributed cluster data consumption method provided by the present invention;
[0047] Figure 6 This is one of the structural schematic diagrams of the data consumption device of the distributed cluster provided by the present invention;
[0048] Figure 7 This is the second structural diagram of the data consumption device of the distributed cluster provided by the present invention;
[0049] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] Aiming at the problem of low message consumption capability of MQTT (Message Queuing Telemetry Transport) server in the prior art, the present invention provides a data consumption method of a distributed cluster, which is applied to a topic distributor TD (Topic-Distributor) server. Figure 1 This is one of the flow charts of the distributed cluster data consumption method provided by the present invention, such as Figure 1 As shown, the method includes:
[0052] Step 110: Receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster.
[0053] Optionally, the target electronic device is any electronic device in the cluster, and the topic list is composed of topic information corresponding to each electronic device, which is stored in the second shared cache by each electronic device and loaded to the TD server by the target electronic device. The topic information can be the electronic device information under the corresponding account, and the electronic device information can be identified in the form of a string.
[0054] Step 120: When the topic list and the client registration information exist in the first shared cache of the TD server, the topic information in the topic list is distributed to each electronic device in the cluster to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information distributed to each of the electronic devices is different.
[0055] Specifically, since the client identification information needs to be specified when expanding multiple processes in the existing solution, if the same client identification information is specified, the MQTT server will think that it is the same electronic device, and the MQTT server will only retain the link of the electronic device that reported the heartbeat for the last time, and disconnect other links. In this way, one process is still consuming data, and the consumption capacity is not enhanced; if different client identification information is specified for different processes, each process may consume according to the same topic list, and repeated consumption may occur, and the consumption capacity is not enhanced. Therefore, in an embodiment of the present invention, all the topic information in the topic list is assigned to different registered electronic devices to ensure that the first topic information assigned to each electronic device is different, so that different electronic devices can consume messages of different topics of the MQTT server based on the assigned first topic information, so as to realize the rapid consumption of MQTT server messages.
[0056] Optionally, distributing the topic information in the topic list to each electronic device in the cluster includes:
[0057] The topic information in the topic list is evenly distributed to each electronic device in the cluster.
[0058] Specifically, when allocating the topic information in the topic list, the topic information may be evenly distributed based on the load pressure of each electronic device to avoid allocating multiple topic information to the same electronic device and overloading the electronic device.
[0059] Optionally, the subject list and the client registration information may be received asynchronously, that is, there is no restriction on the order in which the subject list and the client registration information are received, and the subject list may be received first, and then the client registration information, or the client registration information may be received first, and then the subject list.
[0060] For example, Figure 2 This is the second flow chart of the distributed cluster data consumption method provided by the present invention, such as Figure 2 As shown, taking the distributed cluster including electronic device 1 and electronic device 2, and first receiving the topic list and then receiving the client registration information as an example, the distribution of the topic information in the topic list is achieved by the following steps:
[0061] (1) Receive the subject list sent by electronic device 1 and store it in the first shared cache of the TD server. The subject list is the subject information corresponding to all electronic devices stored in the second shared cache. At this time, there is no registered electronic device in the TD service. Therefore, electronic device 1 directly ends this step after loading the subject list; and receive the client registration information sent by electronic device 1 again, register electronic device 1 in the service list of the TD server. At this time, the subject list has been stored in the first shared cache, and all subject information is allocated to electronic device 1;
[0062] (2) Since electronic device 1 has loaded the subject list into the first shared cache in the TD service, and the first shared cache is locked, the subject list sent by electronic device 2 received by the TD server is empty. The TD server determines that electronic device 1 has been registered, but electronic device 2 has not been registered, and then assigns all subject information to electronic device 1, and then ends this step;
[0063] (3) After completing step (2), the TD server can also receive the client registration information sent by electronic device 2, register electronic device 2 in the service list of the TD server, and the TD service determines that electronic device 1 and electronic device 2 are both registered, then allocates all subject information to electronic device 1 and electronic device 2, and then ends this step, wherein the number of subject information allocated to electronic device 1 and electronic device 2 can be the same or different.
[0064] For example, Figure 3 This is the third flow chart of the distributed cluster data consumption method provided by the present invention, such as Figure 3 As shown, taking the distributed cluster including electronic device 1 and electronic device 2, and first receiving the client registration information and then receiving the topic list as an example, the distribution of the topic information in the topic list is achieved by the following steps:
[0065] (1) Receive the client registration information sent by electronic device 1 and store it in the first shared cache of the TD server. At this time, the first shared cache of the TD server does not store the subject list. Therefore, electronic device 1 loads all subject information from the second shared cache and generates a subject list. The TD server receives the subject list sent by electronic device 1. At this time, the first shared cache has stored the subject list, and electronic device 1 has been registered. All subject information is distributed to electronic device 1, and this step ends.
[0066] (2) Continue to receive the client registration information sent by electronic device 2, and store it in the first shared cache of the TD server. At this time, the subject list has been stored in the first shared cache of the TD server, and electronic device 1 and electronic device 2 have been registered. Then, the TD server allocates all the subject information in the subject list to electronic device 1 and electronic device 2, and ends this step. The number of subject information allocated to electronic device 1 and electronic device 2 can be the same or different.
[0067] Optionally, the client registration information includes client identification information clientid and host information host;
[0068] The method further comprises:
[0069] Based on the client identification information and the host information, determining second topic information that each of the electronic devices needs to subscribe to;
[0070] Based on the second theme information corresponding to each of the electronic devices, the first theme information allocated to each of the electronic devices is updated.
[0071] Specifically, as each electronic device is continuously registered, the topic information assigned to each electronic device is constantly changing. In an embodiment of the present invention, the second topic information of each electronic device can be determined again through the client identification information and the host information, and the first topic information can be updated based on the second topic information, so as to facilitate each electronic device to consume the messages of the MQTT server.
[0072] Optionally, the client identification information is a unique identification of each electronic device, the host information is used to characterize the business line corresponding to each electronic device, and different host information is logically isolated.
[0073] Optionally, the method further comprises:
[0074] Regularly detecting the communication information of each of the registered electronic devices;
[0075] Determine the electronic device that has not updated the communication information within a preset period of time, and delete the client registration information of the electronic device;
[0076] The topic information in the topic list is redistributed to each of the surviving electronic devices.
[0077] Specifically, the TD server can also periodically detect whether the registered electronic device is inactivated. If the electronic device does not update the communication information within a predetermined period of time, the electronic device will be confirmed as not inactivated. The TD server can delete the client registration information of the electronic device and trigger the allocation mechanism again, that is, reallocate all the subject information to each electronic device in stock. The number of first subject information allocated to each electronic device can be different or the same.
[0078] Optionally, the preset time length may be set to three heartbeats. When the TD server sends a detection signal to the electronic device three times and receives no response from the electronic device, the electronic device may be determined to be a non-inactivated electronic device.
[0079] Optionally, the method further comprises:
[0080] After deleting the client registration information of the electronic device, the first subject information corresponding to the electronic device is redistributed to each surviving electronic device.
[0081] Specifically, during the reallocation, the first subject information corresponding to the inactivated electronic device may be reallocated to the surviving electronic devices, and the quantity of the first subject information allocated to each surviving electronic device may be the same or different.
[0082] The data consumption method of a distributed cluster provided by the present invention adds a TD server, and when receiving a topic list and client registration information sent by an electronic device, all topic information in the topic list is evenly distributed to each electronic device, so that the client identification information of each electronic device is different and the subscribed first topic information is different, thereby avoiding repeated consumption of messages from the MQTT server, and improving the consumption capacity of MQTT server messages by expanding the capacity of electronic devices.
[0083] The present invention also provides a distributed cluster data consumption method, which is applied to a target electronic device. Figure 4 This is a fourth flow chart of the distributed cluster data consumption method provided by the present invention, such as Figure 4 As shown, the method includes:
[0084] Step 410: Obtain a topic list from the second shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0085] Step 420: Send the topic list and client registration information to the topic distributor TD server through the client, and lock the shared cache;
[0086] Step 430: Receive first topic information sent by the TD server, where the first topic information is obtained by allocating topic information in the topic list when the TD server has the topic list and the client registration information in the second shared cache;
[0087] Step 440: Generate a subscription request based on the first topic information, and consume data from the MQTT server based on the subscription request.
[0088] Specifically, any electronic device in the cluster can obtain all topic information from the second shared cache and generate a topic list. After sending the topic list and client registration information to the TD server, the second shared cache is locked based on a distributed lock to avoid duplication of topic information in the TD server. After the TD server allocates the topic information, it receives the first topic information of the allocated number, subscribes to the first topic information from the MQTT server, and consumes the messages corresponding to the first topic information.
[0089] Optionally, when sending the topic list to the TD server, dynamic loading can also be performed, that is, the electronic devices in the cluster can load part of the topic information to the TD server. After multiple electronic devices send all the topic information to the TD server, the second shared cache can be locked based on the distributed lock.
[0090] Optionally, when sending the subject list, the electronic device may register the subject list in the TD service through a remote procedure call (RPC).
[0091] Optionally, Figure 5 FIG. 5 is a flow chart of the distributed cluster data consumption method provided by the present invention. Figure 5 As shown, the method also includes:
[0092] Regularly updating the first subject information;
[0093] Receiving second topic information sent by the TD server, where the second topic information is redistributed by the TD server based on the registration information of each client;
[0094] The first subject information is compared with the second subject information, and based on the comparison result, third subject information corresponding to each of the electronic devices is determined, and the third subject information is used to generate a subscription request or cancel a subscription.
[0095] Specifically, after obtaining the first topic information, the electronic device can also receive the second topic information reallocated by the TD server, and based on the comparison result of the first topic information and the second topic information, obtain the third topic information to subscribe to or unsubscribe from the new topic information.
[0096] Alternatively, if Figure 5 As shown, the determining, based on the comparison result, the third subject information corresponding to each of the electronic devices includes:
[0097] If the comparison result includes: first difference topic information that exists in the second topic information and does not exist in the first topic information, the first difference topic information is determined as the third topic information, so that the electronic device subscribes to the third topic information from the MQTT server;
[0098] If the comparison result includes: second difference subject information that does not exist in the second subject information but exists in the first subject information, the second difference subject information is determined as the third subject information, so that the electronic device cancels the subscription to the third subject information based on the subscription to the first subject information.
[0099] Specifically, when the electronic device has subscribed to the first topic information, based on the comparison result, if there is new topic information, that is, the first difference topic information that exists in the second topic information but does not exist in the first topic information, then the electronic device can subscribe to the new topic information from the MQTT server; if the second topic information does not exist but the second difference topic information exists in the first topic information, then the electronic device cancels its subscription to the second difference topic information to avoid repeated consumption.
[0100] The data consumption method of a distributed cluster provided by the present invention generates a subscription request based on the allocated first topic information after sending a topic list and client registration information to the TD server and distributing all topic information on the TD server, so as to consume the data of the MQTT server based on the first topic information, thereby improving the data consumption rate of the MQTT server.
[0101] The present invention also provides a distributed cluster data consumption device, which is applied to a topic distributor TD server. Figure 6 This is one of the structural diagrams of the data consumption device of the distributed cluster provided by the present invention, such as Figure 6 As shown, the data consumption device 600 of the distributed cluster includes: a first receiving module 601 and a distribution module 602, wherein:
[0102] A first receiving module 601 is used to receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster;
[0103] The allocation module 602 is used to allocate the topic information in the topic list to each electronic device in the cluster when the topic list and the client registration information exist in the first shared cache of the TD server, so as to obtain the first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume the data of the MQTT server based on the subscription request, wherein the first topic information allocated to each of the electronic devices is different.
[0104] The data consumption device of the distributed cluster provided by the present invention adds a TD server and, when receiving the topic list and client registration information sent by the electronic device, evenly distributes all the topic information in the topic list to each electronic device, so that the client identification information of each electronic device is different and the subscribed first topic information is different, thereby avoiding repeated consumption of messages from the MQTT server and improving the consumption capacity of the MQTT server messages by expanding the capacity of the electronic device.
[0105] Optionally, the allocation module 602 is specifically configured to:
[0106] The distributing the topic information in the topic list to each electronic device in the cluster includes:
[0107] The topic information in the topic list is evenly distributed to each electronic device in the cluster.
[0108] Optionally, the client registration information includes client identification information and host information.
[0109] Optionally, the data consumption device of the distributed cluster further includes: an update module, the update module being specifically used for:
[0110] Based on the client identification information and the host information, determining second topic information that each of the electronic devices needs to subscribe to;
[0111] Based on the second theme information corresponding to each of the electronic devices, the first theme information allocated to each of the electronic devices is updated.
[0112] Optionally, the data consumption device of the distributed cluster further includes: a detection module, which is specifically used to:
[0113] Regularly detecting the communication information of each of the registered electronic devices;
[0114] Determine the electronic device that has not updated the communication information within a preset period of time, and delete the client registration information of the electronic device;
[0115] The topic information in the topic list is redistributed to each of the surviving electronic devices.
[0116] Optionally, the detection module is specifically used to:
[0117] After deleting the client registration information of the electronic device, the first subject information corresponding to the electronic device is redistributed to each surviving electronic device.
[0118] The present invention also provides a distributed cluster data consumption device, which is applied to a target electronic device. Figure 7This is the second structural diagram of the data consumption device of the distributed cluster provided by the present invention, such as Figure 7 As shown, the data consumption device 700 of the distributed cluster includes: an acquisition module 701, a sending module 702, a second receiving module 703 and a subscription module 704, wherein:
[0119] The acquisition module 701 is used to acquire a topic list from a shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0120] The sending module 702 is used to send the topic list and the client registration information to the topic distributor TD server through the client, and lock the shared cache;
[0121] The second receiving module 703 is used to receive the first theme information sent by the TD server, where the first theme information is obtained by allocating the theme information in the theme list when the TD server has the theme list and the client registration information in the second shared cache;
[0122] The subscription module 704 is used to generate a subscription request based on the first topic information, and consume data from the MQTT server based on the subscription request.
[0123] The data consumption device of the distributed cluster provided by the present invention generates a subscription request based on the allocated first topic information by sending a topic list and client registration information to the TD server, and after the TD server allocates all topic information, so as to consume the data of the MQTT server based on the first topic information, thereby improving the data consumption rate of the MQTT server.
[0124] Optionally, the distributed cluster data consumption device further includes: a comparison module, which is specifically used to:
[0125] Regularly updating the first subject information;
[0126] Receiving second topic information sent by the TD server, where the second topic information is redistributed by the TD server based on the registration information of each client;
[0127] The first subject information is compared with the second subject information, and based on the comparison result, third subject information corresponding to each of the electronic devices is determined, and the third subject information is used to generate a subscription request or cancel a subscription.
[0128] Optionally, the comparison module is specifically used for:
[0129] The determining, based on the comparison result, the third subject information corresponding to each of the electronic devices includes:
[0130] If the comparison result includes: first difference topic information that exists in the second topic information and does not exist in the first topic information, the first difference topic information is determined as the third topic information, so that the electronic device subscribes to the third topic information from the MQTT server;
[0131] If the comparison result includes: second difference subject information that does not exist in the second subject information but exists in the first subject information, the second difference subject information is determined as the third subject information, so that the electronic device cancels the subscription to the third subject information based on the subscription to the first subject information.
[0132] Figure 8 is a schematic diagram of the structure of the electronic device provided by the present invention, such as Figure 8 As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the data consumption method of the distributed cluster, and the method includes:
[0133] Receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster;
[0134] In the case where the topic list and the client registration information exist in the first shared cache of the TD server, the topic information in the topic list is distributed to each electronic device in the cluster to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information distributed to each of the electronic devices is different from each other;
[0135] or,
[0136] Acquire a topic list from the second shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0137] Send the topic list and client registration information to the topic distributor TD server through the client, and lock the shared cache;
[0138] receiving first topic information sent by the TD server, where the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the second shared cache;
[0139] A subscription request is generated based on the first topic information, and data from the MQTT server is consumed based on the subscription request.
[0140] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0141] On the other hand, the present invention further provides a computer program product, the computer program product comprising a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the distributed cluster data consumption method provided by the above methods, the method comprising:
[0142] Receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster;
[0143] In the case where the topic list and the client registration information exist in the first shared cache of the TD server, the topic information in the topic list is distributed to each electronic device in the cluster to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information distributed to each of the electronic devices is different from each other;
[0144] or,
[0145] Acquire a topic list from the second shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0146] Send the topic list and client registration information to the topic distributor TD server through the client, and lock the shared cache;
[0147] receiving first topic information sent by the TD server, where the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the second shared cache;
[0148] A subscription request is generated based on the first topic information, and data from the MQTT server is consumed based on the subscription request.
[0149] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the distributed cluster data consumption method provided by the above methods is implemented, and the method includes:
[0150] Receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster;
[0151] In the case where the topic list and the client registration information exist in the first shared cache of the TD server, the topic information in the topic list is distributed to each electronic device in the cluster to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information distributed to each of the electronic devices is different from each other;
[0152] or,
[0153] Acquire a topic list from the second shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster;
[0154] Send the topic list and client registration information to the topic distributor TD server through the client, and lock the shared cache;
[0155] receiving first topic information sent by the TD server, where the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the second shared cache;
[0156] A subscription request is generated based on the first topic information, and data from the MQTT server is consumed based on the subscription request.
[0157] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0158] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0159] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A distributed cluster data consumption method, characterized in that: Applied to the topic distributor TD server, including: Receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster; the topic list is a collection of corresponding topic information of each electronic device in the cluster; When the topic list and the client registration information exist in the first shared cache of the TD server, the topic information in the topic list is distributed to each registered electronic device in the cluster to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information distributed to each registered electronic device is different from each other.
2. The data consumption method of a distributed cluster according to claim 1, characterized in that: The distributing the topic information in the topic list to each electronic device in the cluster includes: The topic information in the topic list is evenly distributed to each electronic device registered in the cluster.
3. The data consumption method of a distributed cluster according to claim 1 or 2, characterized in that: The client registration information includes client identification information and host information; The method further comprises: Based on the client identification information and the host information, determining second topic information that each of the electronic devices needs to subscribe to; Based on the second theme information corresponding to each of the electronic devices, the first theme information allocated to each of the electronic devices is updated.
4. The data consumption method of a distributed cluster according to claim 1 or 2, characterized in that: The method further comprises: Regularly detecting the communication information of each of the registered electronic devices; Determine the electronic device that has not updated the communication information within a preset period of time, and delete the client registration information of the electronic device; The topic information in the topic list is redistributed to each of the surviving electronic devices.
5. The data consumption method of a distributed cluster according to claim 4, characterized in that: The method further comprises: After deleting the client registration information of the electronic device, the first subject information corresponding to the electronic device is redistributed to each surviving electronic device.
6. A distributed cluster data consumption method, characterized in that: Applied to various electronic devices within the cluster, including: The target electronic device obtains a topic list from the second shared cache, where the topic list is a collection of topic information corresponding to each electronic device in the cluster; The target electronic device sends the topic list to the topic distributor TD server through the client, and each electronic device in the cluster sends client registration information to the TD server, and locks the second shared cache; Each electronic device registered in the cluster receives the first topic information sent by the TD server, where the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the first shared cache; the first topic information allocated to each of the registered electronic devices is different from each other; Each of the registered electronic devices generates a subscription request based on the first topic information, and consumes data from the MQTT server based on the subscription request.
7. The data consumption method of a distributed cluster according to claim 6, characterized in that: The method further comprises: The first topic information is updated regularly, and the regularly updating the first topic information includes the following steps: Receiving second topic information sent by the TD server, where the second topic information is redistributed by the TD server based on the registration information of each client; The first subject information is compared with the second subject information, and based on the comparison result, third subject information corresponding to each electronic device is determined, and the third subject information is used to generate a subscription request or cancel a subscription.
8. The data consumption method of a distributed cluster according to claim 7, characterized in that: The determining, based on the comparison result, the third subject information corresponding to each of the electronic devices includes: If the comparison result includes: first difference topic information that exists in the second topic information and does not exist in the first topic information, the first difference topic information is determined as the third topic information, so that the electronic device subscribes to the third topic information from the MQTT server; If the comparison result includes: second difference subject information that does not exist in the second subject information but exists in the first subject information, the second difference subject information is determined as the third subject information, so that the electronic device cancels the subscription to the third subject information based on the subscription to the first subject information.
9. A distributed cluster data consumption device, characterized in that: Applied to the topic distributor TD server, including: A first receiving module, configured to receive a topic list sent by a target electronic device and client registration information sent by each electronic device in the cluster; the topic list is a collection of corresponding topic information of each electronic device in the cluster; An allocation module is used to allocate the topic information in the topic list to each registered electronic device in the cluster when the topic list and the client registration information exist in the first shared cache of the TD server, so as to obtain first topic information, wherein the first topic information is used to instruct the electronic device to generate a subscription request and consume data from the MQTT server based on the subscription request, wherein the first topic information allocated to each registered electronic device is different from each other.
10. A distributed cluster data consumption device, characterized in that: Applied to various electronic devices within the cluster, including: An acquisition module, configured for the target electronic device to acquire a topic list from the second shared cache, wherein the topic list is a collection of topic information corresponding to each electronic device in the cluster; A sending module, configured for the target electronic device to send the topic list to a topic distributor TD server through a client, and each electronic device in the cluster to send client registration information to the TD server, and to lock the second shared cache; A second receiving module is used for each electronic device registered in the cluster to receive the first topic information sent by the TD server, wherein the first topic information is obtained by allocating the topic information in the topic list when the TD server has the topic list and the client registration information in the first shared cache; the first topic information allocated to each of the registered electronic devices is different from each other; The subscription module is used for each of the registered electronic devices to generate a subscription request based on the first topic information, and consume the data of the MQTT server based on the subscription request.
11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the data consumption method of the distributed cluster as described in any one of claims 1 to 5 is implemented, or the data consumption method of the distributed cluster as described in any one of claims 6 to 8.
Citation Information
Patent Citations
Resource management platform having topics distribution function and its method
CN101064619A
Posting / subscribing system for adding message queue models and working method thereof
CN104092767A