A message subscription method and device based on a ZK server

By monitoring the message publishing and subscription nodes on the ZK server and generating a real-time subscription strategy, the system instability problem caused by the addition of new or higher-level topics on the message subscription side is solved, and dynamic subscription and performance improvement are achieved.

CN114840353BActive Publication Date: 2025-10-10TUS CLOUD CONTROL (BEIJING) TECH LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210368942.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-08
Publication Date
2025-10-10
Estimated Expiration
2042-04-08

AI Technical Summary

Technical Problem

In the prior art, adding a new message topic or subscribing to a higher-level consumption topic at a message subscriber end causes system instability and performance degradation.

Method used

The ZK server is used to dynamically monitor message publishing nodes and subscription nodes, generate real-time publisher and subscriber lists, generate subscription strategies based on the lists and broadcast them to subscribers, and implement dynamic subscription message topics.

Benefits of technology

By dynamically monitoring changes in message publishing nodes and topics, the restart of the message subscriber end is avoided, improving system stability and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114840353B_ABST
    Figure CN114840353B_ABST
Patent Text Reader

Abstract

The embodiment of the present specification discloses a message subscription method and device based on a ZK server, a message publishing end and a message subscribing end register a message publishing node and a message subscribing node in the ZK server respectively, and the dynamic of each message publishing node and each message subscribing node in the ZK server is listened to, so as to obtain a real-time message publishing end list and a message subscribing end list; a message publishing theme list corresponding to the message publishing end list in real time is obtained; a message subscription strategy is generated according to the message publishing theme list and the message subscribing end list; the message subscription strategy is broadcasted to each message subscribing end, so that each message subscribing end subscribes to a to-be-subscribed message theme in the message theme list according to the message subscription strategy. The message subscription method and device based on the ZK server provided by the embodiment of the present specification can dynamically subscribe to a message theme, and each message subscribing end will not cause system or performance instability due to the addition of a message theme or the subscription to a higher-level message theme.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification relate to the field of communication technology, and in particular to a message subscription method and device based on a ZK server. Background Art

[0002] MQTT (Message Queuing Telemetry Transport) is a "lightweight" communication protocol based on the publish / subscribe model. The message publisher and message subscriber are connected to the MQTT middleware server through the MQTT protocol. The message publisher publishes messages to the message topics on the MQTT middleware server. Only when the message subscriber subscribes to the corresponding message topic on the MQTT middleware server can the message subscriber subscribe to the messages published by the message publisher, thereby achieving communication between the message publisher and the message subscriber.

[0003] This message topic is a label for application messages pre-defined by the message subscriber and the message publisher. When the message publisher adds a new message topic, the message subscriber needs to restart the program to subscribe to the new message topic or subscribe to a higher-level message topic, which greatly reduces the stability and performance of the entire system. Summary of the Invention

[0004] In view of this, the embodiments of this specification provide a message subscription method and device based on a ZK server, which is used to solve the system instability and performance problems caused by the message subscriber adding new message topics or subscribing to higher-level consumption topics in the existing technology.

[0005] The embodiments of this specification adopt the following technical solutions:

[0006] This embodiment of the present invention provides a message subscription method based on a ZK server, wherein each message publisher and each message subscriber registers a message publishing node and a message subscription node in the ZK server, respectively. The method includes:

[0007] Monitor the dynamics of each message publishing node and each message subscription node in the ZK server to obtain a real-time message publishing terminal list and a message subscription terminal list according to the monitoring results;

[0008] Obtain a list of message publishing topics corresponding to the message publishing end list in real time;

[0009] Generate a message subscription policy based on the message publishing topic list and the message subscription terminal list;

[0010] The message subscription policy is broadcasted to each of the message subscribers, so that each of the message subscribers subscribes to the message topics to be subscribed included in the message topic list from the MQTT server according to the message subscription policy.

[0011] Furthermore, monitoring the dynamics of each message publishing node and each message subscription node in the ZK server includes:

[0012] The online and offline information of each message publishing node and each message subscription node is monitored to obtain a real-time message publishing terminal list and a message subscription terminal list.

[0013] Furthermore, obtaining a message publishing topic list corresponding to the message publishing terminal list in real time includes:

[0014] When a new online message publishing node is detected, the corresponding new message publishing topic is added to the message publishing topic list;

[0015] Alternatively, when a newly offline message publishing node is monitored, the corresponding message publishing topic is deleted from the message publishing topic list.

[0016] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0017] When a newly offline message publishing node is monitored, determining a message subscriber that has subscribed to the message publishing topic corresponding to the newly offline message publishing node from the message subscriber list;

[0018] The message subscription policy is generated according to the determined message subscription end and the message publishing topic corresponding to the newly offline message publishing node, so that the determined message subscription end cancels the subscription to the message publishing topic corresponding to the newly offline message publishing node to release system resources.

[0019] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0020] The message subscription strategy is generated according to the number of message topics to be subscribed contained in the message publishing topic list and the load information of each message subscriber in the message subscriber list.

[0021] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0022] According to the preset election mechanism, the message subscription master node is elected from the message subscription nodes of the ZK server;

[0023] The message subscription master node generates the message subscription strategy based on the message publishing topic list and the message subscription terminal list using a load balancing algorithm to evenly distribute the message topics to be subscribed to each of the message subscription nodes.

[0024] Furthermore, broadcasting the message subscription policy to each of the message subscribers includes:

[0025] The message subscription master node broadcasts the message subscription policy to each of the message subscription terminals, so that each of the message subscription terminals subscribes to the message topics to be subscribed that need to be subscribed from the MQTT server in a balanced manner according to the message subscription policy.

[0026] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0027] Obtaining characteristic information of the message topics to be subscribed included in the message publishing topic list;

[0028] Selecting a message subscription node that needs to subscribe to the message topic to be subscribed from the message subscription terminal list according to the feature information;

[0029] The message subscription policy is generated according to the selected message subscription node and the characteristic information.

[0030] Furthermore, broadcasting the message subscription policy to each of the message subscribers includes:

[0031] The message subscription policy is broadcast to the message subscription end corresponding to the selected message subscription node, so that the message subscription end subscribes to the message topic to be subscribed from the MQTT server according to the message subscription policy.

[0032] The embodiment of this specification also provides a message subscription device based on a ZK server, wherein each message publisher and each message subscriber respectively registers a message publishing node and a message subscription node in the ZK server, and the device includes:

[0033] A monitoring module monitors the dynamics of each message publishing node and each message subscription node in the ZK server to obtain a real-time message publishing terminal list and a message subscription terminal list according to the monitoring results;

[0034] An acquisition module is used to obtain a message publishing topic list corresponding to the message publishing terminal list in real time;

[0035] A policy generating module, generating a message subscription policy according to the message publishing topic list and the message subscription terminal list;

[0036] The broadcast module broadcasts the message subscription policy to each of the message subscribers, so that each of the message subscribers subscribes to the message topics to be subscribed included in the message topic list from the MQTT server according to the message subscription policy.

[0037] At least one of the above technical solutions adopted in the embodiments of this specification can achieve the following beneficial effects:

[0038] Each message publisher and each message subscriber registers a message publishing node and a message subscription node on the ZK server respectively, and monitors the dynamics of each message publishing node and each message subscription node in the ZK server to obtain a real-time message publisher list and a message subscription list. In this way, the online and offline information of the message publisher and the message subscriber can be monitored, and the real-time message publishing topic list corresponding to the message publisher list can be obtained. A message subscription strategy is generated based on the message publishing topic list and the message subscription list, and the message subscription strategy is broadcast to each message subscriber, so that each message subscriber subscribes to the message topic to be subscribed contained in the message topic list from the MQTT server according to the message subscription strategy.

[0039] In this way, the message subscriber can dynamically monitor the number of message publishing nodes and changes in the message publishing topics through the ZK server, thereby realizing dynamic subscription to message publishing topics. Each message subscriber will not need to restart the message subscription program due to adding new message topics or subscribing to higher-level message topics, which will cause system or performance instability. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The drawings described herein are used to provide a further understanding of the embodiments of this specification and constitute a part of the embodiments of this specification. The illustrative embodiments and descriptions of this specification are used to explain this application and do not constitute an improper limitation on this application. In the drawings:

[0041] Figure 1 This is a diagram showing the overall architecture of a message subscription system based on a ZK server provided in an embodiment of this specification;

[0042] Figure 2 A flowchart of a message subscription method based on a ZK server provided in an embodiment of this specification;

[0043] Figures 3 to 6 A flowchart of a specific application of a message subscription method based on a ZK server provided in an embodiment of this specification;

[0044] Figure 7 A flowchart of a message subscription method based on a ZK server provided in an embodiment of this specification;

[0045] Figure 8This is a structural diagram of a message subscription device based on a ZK server provided in an embodiment of this specification. DETAILED DESCRIPTION

[0046] To make the objectives, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this specification and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this application.

[0047] The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.

[0048] like Figure 1 FIG. 1 is a diagram showing the overall architecture of a message subscription system based on a ZK server according to an embodiment of the present disclosure.

[0049] The message subscription system based on the ZK server includes: multiple message publishing terminals 11, an MQTT server 12, multiple message subscription terminals 13 and a ZK server 14.

[0050] Among them, ZK (ZooKeeper) server refers to a distributed, open source distributed application coordination service. It is a software that provides consistency services for distributed applications. The functions it provides include: configuration maintenance, domain name services, distributed synchronization and group services.

[0051] Generally, in the process of subscribing to message topics, multiple message publishers 11 store their respective published message topics in the MQTT server 12, and multiple message subscribers 13 select the message topics they need to subscribe to from the message topics stored in the MQTT server 12 to subscribe, thereby completing the communication between the message publisher 11 and the message subscriber 13.

[0052] In the ZK server-based message subscription system of this embodiment, multiple message publishers 11 register their corresponding message publishing nodes in the first directory specified by the ZK server 14 and store the published message topics in their respective message publishing nodes. At the same time, the ZK server 14 generates a message topic list and a message publisher list based on the stored message topics.

[0053] Multiple message subscription terminals 13 respectively register their corresponding message subscription nodes in the second directory specified by the ZK server 14, and elect a message subscription master node from each message subscription node according to a preset election mechanism, and the remaining message subscription nodes are message subscription slave nodes.

[0054] During the message topic subscription process, the message subscription master node will monitor the number of message publishing nodes in the specified first directory, and dynamically adjust the message topic subscription plan of each message subscription node according to the changes in the number of message publishing nodes to realize dynamic subscription of message topics.

[0055] Specifically, the message subscription master node reads the message topic list and message publisher list from the ZK server 14 and caches the message publisher list. The message subscription master node uses a load balancing algorithm to evenly distribute the message topics to be subscribed in the message topic list to each message subscriber, broadcasts the final subscription plan for the message topic to be subscribed to each message subscription node, and caches the subscription plan for the message topic to be subscribed.

[0056] After receiving the subscription plan for the message topic to be subscribed, each message subscription node will subscribe to its own list of message topics to be subscribed from the MQTT server 12 according to the subscription plan for the message topic to be subscribed.

[0057] That is, when executing the subscription scheme for the message topics to be subscribed, both the message subscription master node and the message subscription slave node need to execute to subscribe to the message topic lists that they need to subscribe to.

[0058] Based on the above architecture, the solution of this specification is described in detail below.

[0059] like Figure 2 FIG2 is a flow chart of a message subscription method based on a ZK server provided in an embodiment of this specification.

[0060] Wherein, each message publishing end and each message subscription end registers a message publishing node and a message subscription node in the ZK server respectively.

[0061] The message subscription method based on the ZK server may specifically include the following steps:

[0062] S201: monitoring the dynamics of each message publishing node and each message subscription node in the ZK server, and obtaining a real-time message publishing terminal list and a message subscription terminal list according to the monitoring results;

[0063] S202: Obtain a message publishing topic list corresponding to the message publishing end list in real time;

[0064] S203: Generate a message subscription policy according to the message publishing topic list and the message subscription terminal list;

[0065] S204: Broadcast the message subscription policy to each of the message subscribers, so that each of the message subscribers subscribes to the to-be-subscribed message topics included in the message topic list from the MQTT server according to the message subscription policy.

[0066] In the embodiment of this specification, with respect to step S201, monitoring the dynamics of each message publishing node and each message subscribing node in the ZK server may include:

[0067] The online and offline information of each message publishing node and each message subscription node is monitored to obtain a real-time message publishing terminal list and a message subscription terminal list.

[0068] After each message publisher and each message subscriber respectively registers a message publishing node and a message subscription node in the ZK server, the status of each message publisher and each message subscriber in the ZK server is online.

[0069] If a new message publisher and / or information subscriber is added, it means that a new message publisher and / or information subscriber is online. If the message publisher and / or information subscriber is deleted or fails, the status of the message publisher and / or information subscriber in the ZK server is offline.

[0070] In this way, by monitoring the online and offline information of each message publishing node and each message subscription node, a real-time online message publishing terminal list and message subscription terminal list can be obtained.

[0071] Furthermore, monitoring the dynamics of each message publishing node in the ZK server may include:

[0072] The dynamics of the first directory specified in the ZK server are monitored, wherein the first directory specified is a directory specified by each message publishing terminal for registering a message publishing node in the ZK server.

[0073] In a specific application embodiment, monitoring the dynamics of the first directory specified in the ZK server may include:

[0074] The number of message publishing nodes in the specified first directory is monitored.

[0075] Regarding step S202, obtaining a message publishing topic list corresponding to the message publishing end list in real time may specifically include:

[0076] When a new online message publishing node is detected, the corresponding new message publishing topic is added to the message publishing topic list;

[0077] Alternatively, when a newly offline message publishing node is monitored, the corresponding message publishing topic is deleted from the message publishing topic list.

[0078] Correspondingly, as an application embodiment, generating a message subscription policy according to the message publishing topic list and the message subscriber list may include:

[0079] When a newly offline message publishing node is monitored, determining a message subscriber that has subscribed to the message publishing topic corresponding to the newly offline message publishing node from the message subscriber list;

[0080] The message subscription policy is generated according to the determined message subscription end and the message publishing topic corresponding to the newly offline message publishing node, so that the determined message subscription end cancels the subscription to the message publishing topic corresponding to the newly offline message publishing node to release system resources.

[0081] In the embodiments of this specification, the message subscription strategy may refer to a specific implementation method for each message subscriber to subscribe to the message publishing topic to be subscribed.

[0082] When the message subscription master node monitors that the message publishing node is reduced, it means that the message publisher has been deleted. The message subscription master node needs to unsubscribe from the message topic corresponding to the reduced message publisher to release system resources.

[0083] As another application embodiment, generating a message subscription policy according to the message publishing topic list and the message subscriber list may further include:

[0084] When a newly-added online message publishing node is monitored, the message publishing topic corresponding to the newly-added online message publishing node is determined;

[0085] Update the message publishing topic list in real time according to the newly added message publishing topic;

[0086] The message subscription policy is generated according to the updated message publishing topic list and the message subscription terminal list.

[0087] Furthermore, the newly added message publishing topic can be evenly distributed to several message subscription nodes according to the message subscription strategy, so that the several message subscription nodes subscribe to their respective newly added message topics to be subscribed from the MQTT server.

[0088] During this process, if a message subscription node has no new message topics to be subscribed, it does not need to pay attention to the message subscription strategy of this broadcast.

[0089] In the embodiment of this specification, each of the message subscription nodes is registered by a corresponding message subscription end in the second directory specified by the ZK server, and the method may further include:

[0090] The dynamics of the designated second directory are monitored to change the message topic subscription scheme of each message subscription node in real time according to the dynamic changes of the message subscription node.

[0091] Furthermore, monitoring the dynamics of the designated second directory may include:

[0092] When it is monitored that the number of the message subscription slave nodes increases, the current message topic list and the message publishing terminal list in the ZK server are read;

[0093] According to the current number of message subscription nodes and the current message topic list, some message topics subscribed by other message subscription nodes are allocated to the newly added message subscription slave nodes to evenly distribute the message topics subscribed by the current message subscription nodes.

[0094] Furthermore, monitoring the dynamics of the designated second directory may include:

[0095] When it is monitored that the number of the message subscription slave nodes decreases, the current message topic list and the message publishing terminal list in the ZK server are read;

[0096] According to the current number of message subscription nodes and the current message topic list, the message topics subscribed to by the reduced message subscription slave nodes are evenly distributed to the remaining message subscription nodes.

[0097] In the embodiment of this specification, with respect to step S203, generating a message subscription policy according to the message publishing topic list and the message subscriber list may include:

[0098] The message subscription strategy is generated according to the number of message topics to be subscribed contained in the message publishing topic list and the load information of each message subscriber in the message subscriber list.

[0099] To ensure that each subscriber can subscribe to messages in a load-balanced manner, thereby effectively improving the stability of the message subscription system, a corresponding message subscription strategy can be generated based on the number of message topics to be subscribed and the load information of each subscriber. The load information of the subscriber can refer to the current remaining load of the subscriber.

[0100] Specifically, generating a message subscription policy according to the message publishing topic list and the message subscriber list may further include:

[0101] According to the preset election mechanism, the message subscription master node is elected from the message subscription nodes of the ZK server;

[0102] The message subscription master node generates the message subscription strategy based on the message publishing topic list and the message subscription terminal list using a load balancing algorithm to evenly distribute the message topics to be subscribed to each of the message subscription nodes.

[0103] In the embodiment of this specification, the election mechanism of the ZK server can be used to elect a message subscription master node from each message subscription node, and the remaining message subscription nodes are message subscription slave nodes.

[0104] Regarding step S204, broadcasting the message subscription policy to each of the message subscribers may include:

[0105] The message subscription master node broadcasts the message subscription policy to each of the message subscription terminals, so that each of the message subscription terminals subscribes to the message topics to be subscribed that need to be subscribed from the MQTT server in a balanced manner according to the message subscription policy.

[0106] Furthermore, the method may further include:

[0107] When the message subscription master node goes offline, each of the message subscription slave nodes re-elects a new message subscription master node according to the preset election mechanism;

[0108] The new message subscription master node distributes the message topic list subscribed by the offline message subscription master node to each message subscription node in a balanced manner.

[0109] Furthermore, the method may further include:

[0110] The new message subscription master node reads the current message topic list and the message publishing terminal list in the ZK server;

[0111] The new message subscription master node re-formulates a message topic subscription plan based on the current message topic list and the message publishing terminal list;

[0112] The new message subscription master node broadcasts the reformulated message topic subscription plan to each of the message subscription nodes, so that each of the message subscription nodes re-subscribes to its own message topic according to the reformulated message topic subscription plan and cancels the subscription to the subscribed message topic.

[0113] In the embodiment of this specification, with respect to step S203, generating a message subscription policy according to the message publishing topic list and the message subscriber list may further include:

[0114] Obtaining characteristic information of the message topics to be subscribed included in the message publishing topic list;

[0115] Selecting a message subscription node that needs to subscribe to the message topic to be subscribed from the message subscription terminal list according to the feature information;

[0116] The message subscription policy is generated according to the selected message subscription node and the characteristic information.

[0117] The characteristic information of the message topic to be subscribed may refer to the characteristics of the subscription information corresponding to the message topic to be subscribed. For example, it may refer to the special requirements of the subscription information for the message subscriber. In this case, the information topic to be subscribed needs to be subscribed by the specified message subscriber to process the subscription information therein.

[0118] Specifically, broadcasting the message subscription policy to each of the message subscribers may include:

[0119] The message subscription policy is broadcast to the message subscription end corresponding to the selected message subscription node, so that the message subscription end subscribes to the message topic to be subscribed from the MQTT server according to the message subscription policy.

[0120] The embodiment of this specification provides a message subscription method based on the ZK server. Each message publisher and each message subscriber registers a message publishing node and a message subscription node in the ZK server respectively. By monitoring the dynamics of each message publishing node and each message subscription node in the ZK server, a real-time message publisher list and a message subscription list are obtained. In this way, the online and offline information of the message publisher and the message subscriber can be monitored, and a message publishing topic list corresponding to the message publisher list in real time can be obtained. A message subscription strategy is generated according to the message publishing topic list and the message subscription list, and the message subscription strategy is broadcast to each message subscriber, so that each message subscriber subscribes to the message topic to be subscribed contained in the message topic list from the MQTT server according to the message subscription strategy.

[0121] In this way, the message subscriber can dynamically monitor the number of message publishing nodes and changes in the message publishing topics through the ZK server, thereby realizing dynamic subscription to message publishing topics. Each message subscriber will not need to restart the message subscription program due to adding new message topics or subscribing to higher-level message topics, which will cause system or performance instability.

[0122] like Figures 3 to 6 As shown, it is a flowchart of a specific application of a message subscription method based on a ZK server provided in an embodiment of this specification. In this embodiment of this specification, the roadside device is used as the message publishing end, and the cloud control platform is used as the message subscription end.

[0123] In the embodiments of the present specification, the roadside device can be used to perceive road-related information, and specifically can include a roadside sensor, a camera, etc., and can be used to measure perceived vehicle flow, traffic light information, traffic congestion information, weather conditions, etc., which are not limited here.

[0124] The cloud control platform is loaded with multiple message subscription programs, which can serve as multiple message subscription ends. Each message subscription end can process the same or different measurement and perception data.

[0125] In the embodiments of the present specification, the existing roadside device and the message subscription end on the cloud control platform are registered with the corresponding message publishing node and message subscription node in the ZK server, and the message subscription master node is randomly selected from the multiple message subscription nodes by using the election mechanism of the ZK server, and the other message subscription nodes are message subscription slave nodes.

[0126] If a new roadside device is added, the specific message subscription steps between the cloud control platform and the roadside device are as follows:

[0127] S301: The new roadside device registers the corresponding message publishing node in the ZK server;

[0128] S302: The new message publishing node uploads the measurement and perception data to the corresponding message topic of the MQTT server;

[0129] S303: When the message subscription master node listens to the new message publishing node in the ZK server, the corresponding new message topic is obtained;

[0130] S304: The message subscription master node generates a message subscription strategy according to the new message topic by using a load balancing algorithm;

[0131] S305: The message subscription master node broadcasts the message subscription strategy to each message subscription node;

[0132] S306: The message subscription node involved in the message subscription strategy subscribes to the new message topic according to the message subscription strategy.

[0133] That is, the message subscription node involved in the message subscription strategy processes the new measurement and perception data according to the message subscription strategy.

[0134] If a roadside device is deleted, the specific message subscription steps between the cloud control platform and the roadside device are as follows:

[0135] S401: When the roadside device is deleted, the message publishing node registered by the roadside device in the ZK server is deleted;

[0136] S402: The message subscription master node monitors the decrease in the number of message publishing nodes in the ZK server and reads the message topic corresponding to the deleted message publishing node;

[0137] S403: The message subscription master node generates a message subscription policy to cancel subscription to the message topic;

[0138] S404: The message subscription master node broadcasts the message subscription policy to each message subscription node;

[0139] S405: The message subscription node that has subscribed to the message topic cancels its subscription to the message topic according to the received message subscription policy.

[0140] If the current message subscription program of the cloud control platform cannot handle the current amount of data, at least one new message subscription program can be added dynamically. In this case, the specific message subscription steps between the cloud control platform and the roadside equipment are as follows:

[0141] S501: The newly added message subscription program registers the corresponding message subscription node in the ZK server;

[0142] S502: When the message subscription master node monitors a newly added message subscription node, it distributes the current message topics to be subscribed to each message subscription node evenly according to the load balancing algorithm and generates a message subscription policy;

[0143] S503: The message subscription master node broadcasts the message subscription policy to each message subscription node;

[0144] S504: Each message subscription node re-subscribes to the message topic according to the message subscription policy, and cancels the subscription to the subscribed message topic.

[0145] If the message subscription program on the cloud control platform suddenly crashes, or the existing data volume does not require the current number of message subscription programs, and some message subscription programs need to be deleted, in this case, the specific message subscription steps between the cloud control platform and the roadside equipment are as follows:

[0146] S601: The deleted message subscriber deletes the corresponding registered message subscription node from the ZK server;

[0147] S602: Determine whether the deleted message subscription node is a message subscription master node, and obtain a first determination result;

[0148] S603: If the first judgment result is yes, a new message subscription master node is elected from the existing message subscription nodes according to a preset election mechanism;

[0149] S604: If the first judgment result is no, the message subscription master node generates a new message subscription policy according to the load balancing algorithm;

[0150] S605: The message subscription master node broadcasts the message subscription strategy to each message subscription node.

[0151] S606: Each message subscription node re-subscribes to the message topic according to the message subscription strategy, and unsubscribes from the subscribed message topic.

[0152] As shown in the flowchart of a specific application of the message subscription method based on the ZK server provided by the embodiments of the present specification, in the embodiments of the present specification, the cloud control platform is taken as the message publishing end, and the RSU device is taken as the message subscription end. Figure 7

[0153] In the embodiments of the present specification, the cloud control platform is equipped with multiple message publishing programs, which can be taken as multiple message publishing ends. Both the message publishing program and the RSU device register the corresponding message publishing node and message subscription node in the ZK server.

[0154] In a specific application scenario, when the roadside device senses the presence of an obstacle on the road, it will publish the message through the MQTT server. The message subscription program on the cloud control platform will subscribe to it and process the obstacle message to generate vehicle warning information. The cloud control platform needs to publish the vehicle warning information to warn passing vehicles and prevent traffic accidents.

[0155] In this case, the specific message subscription steps between the cloud control platform and the RSU device are as follows:

[0156] S701: The message publishing end obtains the online RSU device list from the ZK server.

[0157] S702: The message publishing end selects the corresponding RSU device from the RSU device list according to the vehicle warning information.

[0158] S703: Generate a message subscription strategy according to the selected RSU device and the vehicle warning information.

[0159] S704: Broadcast the message subscription strategy to the selected RSU device.

[0160] S705: The selected RSU device subscribes to the vehicle warning information from the MQTT server according to the message subscription strategy, and broadcasts the vehicle warning information to the corresponding connected vehicle.

[0161] As shown in the structural diagram of the message subscription device based on the ZK server provided by the embodiments of the present specification, the same inventive idea is used. Figure 8

[0162] ​​Wherein, each message publishing end and each message subscription end registers a message publishing node and a message subscription node in the ZK server respectively, and the device may include:

[0163] The monitoring module 801 monitors the dynamics of each message publishing node and each message subscription node in the ZK server to obtain a real-time message publishing terminal list and a message subscription terminal list according to the monitoring results;

[0164] Acquisition module 802, acquires the message publishing topic list corresponding to the message publishing terminal list in real time;

[0165] A policy generating module 803 generates a message subscription policy according to the message publishing topic list and the message subscription terminal list;

[0166] The broadcast module 804 broadcasts the message subscription policy to each of the message subscribers, so that each of the message subscribers subscribes to the message topics to be subscribed included in the message topic list from the MQTT server according to the message subscription policy.

[0167] Furthermore, monitoring the dynamics of each message publishing node and each message subscription node in the ZK server includes:

[0168] The online and offline information of each message publishing node and each message subscription node is monitored to obtain a real-time message publishing terminal list and a message subscription terminal list.

[0169] Furthermore, obtaining a message publishing topic list corresponding to the message publishing terminal list in real time includes:

[0170] When a new online message publishing node is detected, the corresponding new message publishing topic is added to the message publishing topic list;

[0171] Alternatively, when a newly offline message publishing node is monitored, the corresponding message publishing topic is deleted from the message publishing topic list.

[0172] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0173] When a newly offline message publishing node is monitored, determining a message subscriber that has subscribed to the message publishing topic corresponding to the newly offline message publishing node from the message subscriber list;

[0174] The message subscription policy is generated according to the determined message subscription end and the message publishing topic corresponding to the newly offline message publishing node, so that the determined message subscription end cancels the subscription to the message publishing topic corresponding to the newly offline message publishing node to release system resources.

[0175] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0176] The message subscription strategy is generated according to the number of message topics to be subscribed contained in the message publishing topic list and the load information of each message subscriber in the message subscriber list.

[0177] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0178] According to the preset election mechanism, the message subscription master node is elected from the message subscription nodes of the ZK server;

[0179] The message subscription master node generates the message subscription strategy based on the message publishing topic list and the message subscription terminal list using a load balancing algorithm to evenly distribute the message topics to be subscribed to each of the message subscription nodes.

[0180] Furthermore, broadcasting the message subscription policy to each of the message subscribers includes:

[0181] The message subscription master node broadcasts the message subscription policy to each of the message subscription terminals, so that each of the message subscription terminals subscribes to the message topics to be subscribed that need to be subscribed from the MQTT server in a balanced manner according to the message subscription policy.

[0182] Furthermore, a message subscription policy is generated according to the message publishing topic list and the message subscriber list, including:

[0183] Obtaining characteristic information of the message topics to be subscribed included in the message publishing topic list;

[0184] Selecting a message subscription node that needs to subscribe to the message topic to be subscribed from the message subscription terminal list according to the feature information;

[0185] The message subscription policy is generated according to the selected message subscription node and the characteristic information.

[0186] Furthermore, broadcasting the message subscription policy to each of the message subscribers includes:

[0187] The message subscription strategy is broadcasted to the message subscription end corresponding to the selected message subscription node, so that the message subscription end subscribes to the to-be-subscribed message topic from the MQTT server according to the message subscription strategy.

[0188] The message subscription device based on the ZK server provided by the embodiments of the present specification registers the message publishing node and the message subscription node in the ZK server respectively by each message publishing end and each message subscription end, and listens to the dynamic of each message publishing node and each message subscription node in the ZK server to obtain the real-time message publishing end list and the message subscription end list. In this way, the on-and-off line information of the message publishing end and the message subscription end can be listened to, the message publishing topic list corresponding to the message publishing end list in real time can be obtained, and the message subscription strategy can be generated according to the message publishing topic list and the message subscription end list. The message subscription strategy is broadcasted to each message subscription end, so that each message subscription end subscribes to the to-be-subscribed message topic included in the message topic list from the MQTT server according to the message subscription strategy.

[0189] In this way, the message subscription end can dynamically monitor the change of the number of message publishing nodes and the publishing message topic through the ZK server, and dynamic subscription of the message publishing topic is realized. Each message subscription end does not need to restart the message subscription program because of the newly-added message topic or the subscription of the higher-level message topic, and the system or performance instability is caused.

[0190] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different than the order in the embodiments and still achieve the desired result. In addition, the processes depicted in the figures do not necessarily require the particular order shown or sequential order to achieve the desired results. In some implementations, multitasking and parallel processing can be advantageous or possible.

[0191] Each of the embodiments in the present specification is described in a progressive manner, and the same and similar parts between each embodiment can be referred to each other. Each embodiment focuses on the difference from other embodiments. Especially, the device, electronic device, and non-volatile computer storage medium embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.

[0192] The apparatus, electronic device, and non-volatile computer storage medium provided in the embodiments of this specification correspond to the method. Therefore, the apparatus, electronic device, and non-volatile computer storage medium also have similar beneficial technical effects as the corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the corresponding apparatus, electronic device, and non-volatile computer storage medium will not be repeated here.

[0193] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (e.g., improvements to circuit structures like diodes, transistors, and switches) or software improvements (e.g., improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using a hardware module. For example, a programmable logic device (PLD) (e.g., a field programmable gate array (FPGA)) is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD through their own programming, eliminating the need for a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages ​​and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.

[0194] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.

[0195] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0196] For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing this application, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0197] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0198] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0199] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0200] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0201] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0202] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0203] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0204] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0205] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0206] The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.

[0207] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.

Claims

1. A message subscription method based on ZK server, characterized in that: Each message publisher and each message subscriber registers a message publishing node and a message subscription node on the ZK server respectively. The method includes: Monitor the dynamics of each message publishing node and each message subscription node in the ZK server to obtain a real-time message publishing terminal list and a message subscription terminal list according to the monitoring results; Obtain a list of message publishing topics corresponding to the message publishing end list in real time; Generate a message subscription policy based on the message publishing topic list and the message subscription terminal list; Broadcasting the message subscription policy to each of the message subscribers, so that each of the message subscribers subscribes to the message topics to be subscribed included in the message topic list from the MQTT server according to the message subscription policy; Each of the message subscription nodes is registered by a corresponding message subscription end in a second directory specified by the ZK server, and the method further includes: Monitor the dynamics of the designated second directory to change the message topic subscription scheme of each message subscription node in real time according to the dynamic changes of the message subscription node; Monitoring the dynamics of the designated second directory includes: When it is monitored that the number of the message subscription slave nodes increases, the current message topic list and the message publishing terminal list in the ZK server are read; According to the current number of message subscription nodes and the current message topic list, some message topics subscribed by other message subscription nodes are allocated to the newly added message subscription slave nodes to evenly distribute the message topics subscribed by the current message subscription nodes.

2. The method according to claim 1, wherein Monitoring the dynamics of each message publishing node and each message subscription node in the ZK server includes: The online and offline information of each message publishing node and each message subscription node is monitored to obtain a real-time message publishing terminal list and a message subscription terminal list.

3. The method according to claim 2, wherein Obtain the message publishing topic list corresponding to the message publishing end list in real time, including: When a new online message publishing node is detected, the corresponding new message publishing topic is added to the message publishing topic list; Alternatively, when a newly offline message publishing node is monitored, the corresponding message publishing topic is deleted from the message publishing topic list.

4. The method according to claim 3, wherein Generating a message subscription policy according to the message publishing topic list and the message subscriber list includes: When a newly offline message publishing node is monitored, determining a message subscriber that has subscribed to the message publishing topic corresponding to the newly offline message publishing node from the message subscriber list; The message subscription policy is generated according to the determined message subscription end and the message publishing topic corresponding to the newly offline message publishing node, so that the determined message subscription end cancels the subscription to the message publishing topic corresponding to the newly offline message publishing node to release system resources.

5. The method according to claim 1, wherein Generating a message subscription policy according to the message publishing topic list and the message subscriber list includes: The message subscription strategy is generated according to the number of message topics to be subscribed contained in the message publishing topic list and the load information of each message subscriber in the message subscriber list.

6. The method according to claim 1, wherein Generating a message subscription policy according to the message publishing topic list and the message subscriber list includes: According to the preset election mechanism, the message subscription master node is elected from the message subscription nodes of the ZK server; The message subscription master node generates the message subscription strategy based on the message publishing topic list and the message subscription terminal list using a load balancing algorithm to evenly distribute the message topics to be subscribed to each of the message subscription nodes.

7. The method according to claim 6, wherein Broadcasting the message subscription policy to each of the message subscription terminals includes: The message subscription master node broadcasts the message subscription policy to each of the message subscription terminals, so that each of the message subscription terminals subscribes to the message topics to be subscribed that need to be subscribed from the MQTT server in a balanced manner according to the message subscription policy.

8. The method according to claim 1, wherein Generating a message subscription policy according to the message publishing topic list and the message subscriber list includes: Obtaining characteristic information of the message topics to be subscribed included in the message publishing topic list; Selecting a message subscription node that needs to subscribe to the message topic to be subscribed from the message subscription terminal list according to the feature information; The message subscription policy is generated according to the selected message subscription node and the characteristic information.

9. The method according to claim 8, wherein Broadcasting the message subscription policy to each of the message subscribers includes: The message subscription policy is broadcast to the message subscription end corresponding to the selected message subscription node, so that the message subscription end subscribes to the message topic to be subscribed from the MQTT server according to the message subscription policy.

10. A message subscription device based on a ZK server, used in the message subscription method based on a ZK server according to any one of claims 1 to 9, characterized in that: Each message publishing terminal and each message subscription terminal registers a message publishing node and a message subscription node on the ZK server respectively, and the device includes: A monitoring module monitors the dynamics of each message publishing node and each message subscription node in the ZK server to obtain a real-time message publishing terminal list and a message subscription terminal list according to the monitoring results; An acquisition module is used to obtain a message publishing topic list corresponding to the message publishing terminal list in real time; A policy generating module, generating a message subscription policy according to the message publishing topic list and the message subscription terminal list; The broadcast module broadcasts the message subscription policy to each of the message subscribers, so that each of the message subscribers subscribes to the message topics to be subscribed included in the message topic list from the MQTT server according to the message subscription policy.

Citation Information

Patent Citations

  • Publisher / subscriber real-time mutual discovery method without center nodes under real-time system

    CN101656749A

  • Electronic device, zk node information notification method, system, and storage medium

    WO2019169762A1