Distributed MQTT cluster control method

Through the distributed MQTT cluster control method, the load balancer and elastic KV database are used to solve the problems of high coupling, poor scalability and high availability of MQTT clusters in the existing technology, and the scalability, simple architecture and high availability are achieved, and the improvement of the scalability is achieved. Read and write performance and access capability.

CN119071295APending Publication Date: 2024-12-03GUANGZHOU BINGO SOFTWARE
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411162443.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-23
Publication Date
2024-12-03

AI Technical Summary

Technical Problem

Existing MQTT clusters have problems such as high coupling, poor scalability, complex architecture, difficult maintenance and poor high availability in large-scale deployment scenarios, especially when business peaks and troughs cannot be dynamically adjusted.

Method used

The distributed MQTT cluster control method is adopted, and the broker node is connected through a load balancer. The elastic KV database is used to realize message storage and separation, and message routing and cache based on subscription relationships is used to dynamically add stateless containers and FaaS operators to meet business needs. Ensure transaction consistency and high availability with distributed locking and strong consistency.

Benefits of technology

It realizes the MQTT cluster's strong scalability, simple architecture, and improved read and write performance, reduces costs, and improves the ability of massive MQTT devices and message access, ensuring high availability and transaction consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119071295A_ABST
    Figure CN119071295A_ABST
Patent Text Reader

Abstract

The invention discloses a distributed MQTT cluster control method, which comprises the following steps that: a publisher is connected with any broker node in an MQTT cluster through a load balancer and publishes a message; the subscriber is connected with the broker node in the MQTT cluster through the load balancer, and receives a message sent by the broker node; the Broker node receives and stores the message published by the publisher in a KV database; the Broker node monitors the corresponding message theme based on the subscription relationship between the corresponding subscriber and the message theme; and when a new message of the subscribed message theme appears in the KV database, the broker node obtains the new message and sends the new message to the corresponding subscriber. According to the method, the message data of the MQTT cluster are stripped and stored in the elastic KV database, calculation and storage separation is realized, and by means of the distributed lock and high consistency characteristics of the elastic KV database, the transaction consistency and high availability of the MQTT cluster are guaranteed, and the flexibility of the MQTT cluster is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of MQTT clusters, and in particular relates to a distributed MQTT cluster control method. Background Art

[0002] When the existing MQTT clusters such as EMQX and other mainstream open source solutions are formed, their MQTT business components and data storage components are coupled on one machine, and the cluster is formed in a master-slave mode, and the master-slave mode is generally a core data node and a replication node. However, for large-scale deployment scenarios, the MQTT cluster formed by the master-slave architecture has a high degree of coupling and poor scalability.

[0003] The MQTT cluster built with a master-slave architecture has other disadvantages:

[0004] Complex architecture: Each node has a master node and a slave node, which increases the complexity of the deployment architecture. The star architecture and mesh architecture derived from the master-slave architecture will bring more complex architectural topology relationships, increasing the difficulty of cluster maintenance.

[0005] Poor scalability: Since each node has a designated role and topological relationship, it is impossible to expand the capacity of nodes during business peaks or reduce the capacity of nodes during business troughs.

[0006] Poor high availability: Once the core data node in the master-slave architecture fails, the entire MQTT cluster will be unavailable. Summary of the invention

[0007] In order to overcome the above technical defects, the present invention provides a distributed MQTT cluster control method.

[0008] In order to solve the above problems, the present invention is implemented according to the following technical solutions:

[0009] A distributed MQTT cluster control method comprises the following steps:

[0010] The publisher connects to any broker node in the MQTT cluster through the load balancer and publishes the message;

[0011] The subscriber connects to the broker node in the MQTT cluster through the load balancer and receives the messages sent by the broker node;

[0012] The Broker node receives and stores the messages published by the publisher in the KV database;

[0013] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0014] When a new message of a subscribed message topic appears in the KV database, the broker node obtains the new message and sends it to the corresponding subscriber.

[0015] Furthermore, the method further comprises the steps of:

[0016] Broker nodes are grouped based on the subscribed message topics, where broker nodes in the same business domain subscribe to the same message topics;

[0017] The broker node obtains the data of the corresponding message topic from the KV database according to the subscribed message topic and caches it;

[0018] When receiving a request from a client, the load balancer determines the business domain corresponding to the client request based on the prefix of the subscribed message topic and the content of the client request, and routes the client request to the corresponding business domain.

[0019] Furthermore, the method further comprises the steps of:

[0020] When the message publishing mode is broadcast mode, each broker node elects a leader node;

[0021] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0022] When a new message of a subscribed message topic appears in the KV database, the broker nodes in the corresponding business domain obtain and send the new message to the corresponding subscriber, and write the first sending completion flag to the KV database;

[0023] When the Leader node hears the first sending completion flag, it executes the message deletion operation in the KV database.

[0024] Furthermore, the method further comprises the steps of:

[0025] When the message publishing mode is shared mode, each broker node elects a leader node;

[0026] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0027] When a new message of a subscribed message topic appears in the KV database, each broker node in the corresponding business domain grabs the lock for the new message;

[0028] The broker node that grabs the message lock sends the new message to its corresponding subscriber and writes the second sending completion flag to the KV database;

[0029] When the Leader node detects the second sending completion flag, it executes the message deletion operation in the KV database.

[0030] Furthermore, the MQTT cluster includes a fixed operator, a broker node is set on the fixed operator, and the fixed operator is used to store cache data obtained from the KV database.

[0031] Furthermore, the MQTT cluster also includes stateless container operators and FaaS operators.

[0032] The stateless container operator is set in the container, and the broker node is set on the stateless container operator. The stateless container operator is used to store temporary cache data.

[0033] The FaaS operator is set on the FaaS platform, the broker node is set on the FaaS operator, and the FaaS operator is used to store temporary cache data.

[0034] Furthermore, during business peaks, the MQTT cluster is elastically expanded, including the following steps:

[0035] The controller monitors the load balancer and obtains the number of messages currently flowing through the load balancer;

[0036] The controller dynamically adds stateless container operators and FaaS operators, and adds broker nodes to the stateless container operators and FaaS operators.

[0037] The load balancer routes client requests to the newly added stateless container operator or FaaS operator;

[0038] The controller dynamically adds KV nodes in the KV database, and the broker nodes in the newly added stateless container operators or FaaS operators establish connections with the newly added KV nodes for communication.

[0039] The present invention also provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0040] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.

[0041] Compared with the prior art, the present invention has the following beneficial effects:

[0042] The present invention discloses a distributed MQTT cluster control method, comprising the steps of: a publisher connects to any broker node in the MQTT cluster through a load balancer and publishes a message; a subscriber connects to a broker node in the MQTT cluster through a load balancer and receives a message sent by the broker node; a broker node receives and stores the message published by the publisher in a KV database; the broker node monitors the corresponding message subject based on the subscription relationship between the corresponding subscriber and the message subject; when a new message of the subscribed message subject appears in the KV database, the broker node obtains the new message and sends it to the corresponding subscriber. The message data of the MQTT cluster is stripped and stored in an elastic KV database to realize the separation of computing and storage, and the distributed lock and strong consistency characteristics of the elastic KV database are used to ensure the transaction consistency and high availability of the MQTT cluster and enhance the scalability of the MQTT cluster. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The specific embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings, wherein:

[0044] Figure 1 This is a flow chart of the distributed MQTT cluster control method described in Example 1;

[0045] Figure 2 This is a subscription diagram of the distributed MQTT cluster control method described in Example 1;

[0046] Figure 3 This is a schematic diagram of accurate caching of the distributed MQTT cluster control method described in Example 1;

[0047] Figure 4 This is a schematic diagram of message publishing when the message publishing mode is the broadcast mode in the distributed MQTT cluster control method described in Example 1;

[0048] Figure 5 This is a schematic diagram of message publishing when the message publishing mode is the sharing mode in the distributed MQTT cluster control method described in Example 1;

[0049] Figure 6 This is a structural diagram of the computer device described in Example 2. DETAILED DESCRIPTION

[0050] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.

[0051] Example 1

[0052] This embodiment discloses a distributed MQTT cluster control method, such as Figure 1 and 2 , including the steps of:

[0053] S1. The publisher connects to any broker node in the MQTT cluster through a load balancer and publishes a message.

[0054] S2. The subscriber connects to the broker node in the MQTT cluster through the load balancer and receives the messages sent by the broker node.

[0055] S3. The Broker node receives and stores the messages published by the publisher in the KV database.

[0056] S4. The Broker node monitors the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic.

[0057] S5. When a new message of the subscribed message topic appears in the KV database, the broker node obtains the new message and sends it to the corresponding subscriber.

[0058] In one embodiment, if Figure 3 , further comprising the steps of:

[0059] Broker nodes are grouped based on the subscribed message topics, where broker nodes in the same business domain subscribe to the same type of message topics.

[0060] Broker nodes obtain the data of the corresponding message topics from the KV database according to the subscribed message topics and cache them to improve data reading performance. Broker nodes in the same business domain subscribe to the same message topics and obtain the data of the same message topics from the KV database to achieve accurate caching and effectively maintain the heat of the cache, avoiding invalid cache of broker nodes due to frequent switching of client requests.

[0061] When receiving a request from a client, the load balancer determines the business domain corresponding to the client request based on the prefix of the subscribed message topic and the content of the client request, and routes the client request to the corresponding business domain to avoid re-caching or invalidating the cache on the broker node.

[0062] In one embodiment, if Figure 4 When the message publishing mode is broadcast mode, new messages of the same message topic are sent to all subscribers who subscribe to the topic, including the steps:

[0063] When the message publishing mode is broadcast mode, each broker node elects based on the distributed lock of the KV database. The broker node that obtains the leader lock is the leader node. The leader node is responsible for executing the deletion operation of the new message.

[0064] The Broker node listens to the corresponding message topics based on the connected subscribers and the subscription relationship between the subscribers and the message topics they subscribe to.

[0065] In broadcast mode, when a new message msg1 of the subscribed message topic topic1 appears in the KV database, all broker nodes in the business domain that have subscribed to the message topic topic1 obtain the new message msg1. Each broker node sends the new message msg1 to all corresponding subscribers and writes the first sending completion identifier ack / topic1 / msg1 / broker1 to the KV database. The first sending completion identifier records the sending completion information of a broker node for a message under a certain topic.

[0066] When the Leader node monitors the first sending completion flag, it determines whether all broker nodes based on the subscription relationship have completed message sending. If all broker nodes have completed message sending, the message deletion operation is performed in the KV database; otherwise, it waits for all broker nodes to complete message sending.

[0067] In one embodiment, if Figure 5 When the message publishing mode is shared mode, new messages of the same message topic are sent only to one of the subscribers and will not be sent to two subscribers repeatedly, including the following steps:

[0068] When the message publishing mode is shared mode, each broker node elects based on the distributed lock of the KV database. The broker node that obtains the leader lock is the leader node, and the leader node is responsible for executing the deletion operation of new messages.

[0069] The Broker node listens to the corresponding message topics based on the connected subscribers and the subscription relationship between the subscribers and the message topics they subscribe to.

[0070] When a new message msg2 of the subscribed message topic topic2 appears in the KV database, each broker node in the business domain that has subscribed to the message topic topic2 will grab the lock for the new message msg2. Only the broker node that grabs the message lock share_lock / topic2 / msg2 can publish the message. The message lock records the unique key value of the new message msg2 under the message topic topic2.

[0071] The broker node that grabs the message lock sends the new message msg2 to one of the subscribers through the load balancer according to the number of local subscribers, and writes the second sending completion flag ack / topic2 / msg2 to the KV database. The second sending completion flag records the sending completion information of a certain broker node for a certain message under a certain topic.

[0072] When the Leader node detects the second sending completion flag, it executes the message deletion operation in the KV database.

[0073] In one of the embodiments, the MQTT cluster includes a fixed operator, which is a carrier for executing a broker node program. The fixed operator can be deployed in a virtual machine or a physical machine for a long time. The broker node is set on the fixed operator, and the fixed operator is used to store cached data obtained from the KV database.

[0074] In one embodiment, the MQTT cluster also includes a stateless container operator and a FaaS operator (functional computing). The stateless container operator is set in the container, can be elastically scaled, and is easy to recycle and rebuild; the broker node is set on the stateless container operator, and the stateless container operator is used to store temporary cache data, which is usually used during business peaks and / or business troughs to perform rapid scaling and respond to business pressure. The FaaS operator is set on the FaaS platform, and the broker node is set on the FaaS operator, and the FaaS operator is used to store temporary cache data.

[0075] In one embodiment, during business peak, the MQTT cluster is elastically expanded, including the following steps:

[0076] The cluster controller monitors the load balancer and obtains the number of messages currently flowing through the load balancer.

[0077] The cluster controller dynamically adds stateless container operators and FaaS operators, and adds broker nodes to the stateless container operators and FaaS operators to respond to the expanded business needs and support the read pressure brought by business expansion based on the accurate data caching capabilities of the business domain. The cluster controller can provide elastic scheduling capabilities for stateless container operators and FaaS operators.

[0078] The load balancer routes client requests to the newly added stateless container operator or FaaS operator;

[0079] The controller dynamically adds KV nodes in the KV database. The newly added stateless container operator or broker node in the FaaS operator establishes a connection with the newly added KV node for communication, thereby increasing data writing capabilities.

[0080] The distributed MQTT cluster control method disclosed in the present invention strips the message data of the MQTT cluster and stores it in an elastic KV database to achieve separation of computing and storage, and uses the distributed lock and strong consistency characteristics of the elastic KV database to ensure the transaction consistency and high availability of the MQTT cluster and enhance the scalability of the MQTT cluster. The present invention can achieve separation of computing and storage, has a simple architecture and strong scalability, improves read performance based on precise caching, and improves write performance based on an elastic KV database. It can improve access capabilities and reduce costs for scenarios with massive MQTT devices and message access.

[0081] Example 2

[0082] This embodiment discloses a computer device, which may be a server or terminal integrated with a scheduler, and its internal structure diagram may be as follows: Figure 6 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as the mapping relationship between the shared video memory area and the virtual machine, the total load of the virtual machine, etc. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a distributed MQTT cluster control method is implemented.

[0083] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0084] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:

[0085] The publisher connects to any broker node in the MQTT cluster through the load balancer and publishes the message;

[0086] The subscriber connects to the broker node in the MQTT cluster through the load balancer and receives the messages sent by the broker node;

[0087] The Broker node receives and stores the messages published by the publisher in the KV database;

[0088] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0089] When a new message of a subscribed message topic appears in the KV database, the broker node obtains the new message and sends it to the corresponding subscriber.

[0090] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0091] Broker nodes are grouped based on the subscribed message topics, where broker nodes in the same business domain subscribe to the same message topics;

[0092] The broker node obtains the data of the corresponding message topic from the KV database according to the subscribed message topic and caches it;

[0093] When receiving a request from a client, the load balancer determines the business domain corresponding to the client request based on the prefix of the subscribed message topic and the content of the client request, and routes the client request to the corresponding business domain.

[0094] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0095] When the message publishing mode is broadcast mode, each broker node elects a leader node;

[0096] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0097] When a new message of a subscribed message topic appears in the KV database, the broker nodes in the corresponding business domain obtain and send the new message to the corresponding subscriber, and write the first sending completion flag to the KV database;

[0098] When the Leader node hears the first sending completion flag, it executes the message deletion operation in the KV database.

[0099] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0100] When the message publishing mode is shared mode, each broker node elects a leader node;

[0101] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0102] When a new message of a subscribed message topic appears in the KV database, each broker node in the corresponding business domain grabs the lock for the new message;

[0103] The broker node that grabs the message lock sends the new message to its corresponding subscriber and writes the second sending completion flag to the KV database;

[0104] When the Leader node detects the second sending completion flag, it executes the message deletion operation in the KV database.

[0105] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:

[0106] The controller monitors the load balancer and obtains the number of messages currently flowing through the load balancer;

[0107] The controller dynamically adds stateless container operators and FaaS operators, and adds broker nodes to the stateless container operators and FaaS operators.

[0108] The load balancer routes client requests to the newly added stateless container operator or FaaS operator;

[0109] The controller dynamically adds KV nodes in the KV database, and the broker nodes in the newly added stateless container operators or FaaS operators establish connections with the newly added KV nodes for communication.

[0110] Example 3

[0111] This embodiment discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0112] The publisher connects to any broker node in the MQTT cluster through the load balancer and publishes the message;

[0113] The subscriber connects to the broker node in the MQTT cluster through the load balancer and receives the messages sent by the broker node;

[0114] The Broker node receives and stores the messages published by the publisher in the KV database;

[0115] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0116] When a new message of a subscribed message topic appears in the KV database, the broker node obtains the new message and sends it to the corresponding subscriber.

[0117] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:

[0118] Broker nodes are grouped based on the subscribed message topics, where broker nodes in the same business domain subscribe to the same message topics;

[0119] The broker node obtains the data of the corresponding message topic from the KV database according to the subscribed message topic and caches it;

[0120] When receiving a request from a client, the load balancer determines the business domain corresponding to the client request based on the prefix of the subscribed message topic and the content of the client request, and routes the client request to the corresponding business domain.

[0121] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:

[0122] When the message publishing mode is broadcast mode, each broker node elects a leader node;

[0123] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0124] When a new message of a subscribed message topic appears in the KV database, the broker nodes in the corresponding business domain obtain and send the new message to the corresponding subscriber, and write the first sending completion flag to the KV database;

[0125] When the Leader node hears the first sending completion flag, it executes the message deletion operation in the KV database.

[0126] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:

[0127] When the message publishing mode is shared mode, each broker node elects a leader node;

[0128] The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic;

[0129] When a new message of a subscribed message topic appears in the KV database, each broker node in the corresponding business domain grabs the lock for the new message;

[0130] The broker node that grabs the message lock sends the new message to its corresponding subscriber and writes the second sending completion flag to the KV database;

[0131] When the Leader node detects the second sending completion flag, it executes the message deletion operation in the KV database.

[0132] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:

[0133] The controller monitors the load balancer and obtains the number of messages currently flowing through the load balancer;

[0134] The controller dynamically adds stateless container operators and FaaS operators, and adds broker nodes to the stateless container operators and FaaS operators.

[0135] The load balancer routes client requests to the newly added stateless container operator or FaaS operator;

[0136] The controller dynamically adds KV nodes in the KV database, and the broker nodes in the newly added stateless container operators or FaaS operators establish connections with the newly added KV nodes for communication.

[0137] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0138] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0139] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

[0140] The above description is only a preferred embodiment of the present invention and does not limit the present invention in any form. Therefore, any modification, equivalent change and modification made to the above embodiment based on the technical essence of the present invention without departing from the technical solution of the present invention shall still fall within the scope of the technical solution of the present invention.

Claims

1. A distributed MQTT cluster control method, characterized in that: Includes steps: The publisher connects to any broker node in the MQTT cluster through the load balancer and publishes the message; The subscriber connects to the broker node in the MQTT cluster through the load balancer and receives the messages sent by the broker node; The Broker node receives and stores the messages published by the publisher in the KV database; The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic; When a new message of a subscribed message topic appears in the KV database, the broker node obtains the new message and sends it to the corresponding subscriber.

2. The distributed MQTT cluster control method according to claim 1, characterized in that: Also includes the steps: Broker nodes are grouped based on the subscribed message topics, where broker nodes in the same business domain subscribe to the same message topics; The broker node obtains the data of the corresponding message topic from the KV database according to the subscribed message topic and caches it; When receiving a request from a client, the load balancer determines the business domain corresponding to the client request based on the prefix of the subscribed message topic and the content of the client request, and routes the client request to the corresponding business domain.

3. The distributed MQTT cluster control method according to claim 2, characterized in that: Also includes the steps: When the message publishing mode is broadcast mode, each broker node elects a leader node; The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic; When a new message of a subscribed message topic appears in the KV database, the broker nodes in the corresponding business domain obtain and send the new message to the corresponding subscriber, and write the first sending completion flag to the KV database; When the Leader node hears the first sending completion flag, it executes the message deletion operation in the KV database.

4. The distributed MQTT cluster control method according to claim 2, characterized in that: Also includes the steps: When the message publishing mode is shared mode, each broker node elects a leader node; The Broker node listens to the corresponding message topic based on the subscription relationship between the corresponding subscriber and the message topic; When a new message of a subscribed message topic appears in the KV database, each broker node in the corresponding business domain grabs the lock for the new message; The broker node that grabs the message lock sends the new message to its corresponding subscriber and writes the second sending completion flag to the KV database; When the Leader node detects the second sending completion flag, it executes the message deletion operation in the KV database.

5. The distributed MQTT cluster control method according to any one of claims 3 or 4, characterized in that: The MQTT cluster includes fixed operators, on which broker nodes are set. The fixed operators are used to store cached data obtained from the KV database.

6. The distributed MQTT cluster control method according to claim 5, characterized in that: The MQTT cluster also includes stateless container operators and FaaS operators. The stateless container operator is set in the container, and the broker node is set on the stateless container operator. The stateless container operator is used to store temporary cache data. The FaaS operator is set on the FaaS platform, the broker node is set on the FaaS operator, and the FaaS operator is used to store temporary cache data.

7. The distributed MQTT cluster control method according to claim 6, characterized in that: During business peaks, the MQTT cluster is elastically expanded, including the following steps: The controller monitors the load balancer and obtains the number of messages currently flowing through the load balancer; The controller dynamically adds stateless container operators and FaaS operators, and adds broker nodes to the stateless container operators and FaaS operators. The load balancer routes client requests to the newly added stateless container operator or FaaS operator; The controller dynamically adds KV nodes in the KV database, and the broker nodes in the newly added stateless container operators or FaaS operators establish connections with the newly added KV nodes for communication.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Multi-container communication method and system based on MQTT protocol

    CN120416322A