Multi-instance control method and device based on Node-RED and storage medium
By building a multi-instance control method based on Next.js and Docker containers, the problem of Node-RED single instance deployment is solved, independent operation and data isolation between multiple instances are achieved, and the stability of the system and resource utilization efficiency are improved.
Patent Information
- Application Number
- CN202510306171.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-07-01
AI Technical Summary
Node-RED only supports single-instance deployment, resulting in uneven resource allocation, performance bottlenecks, difficulty in process isolation, mutual interference between variables and data, and cannot meet the needs of multi-task concurrent processing.
The control panel is built based on the full-stack framework Next.js, and multiple instance control is achieved using cloud databases and Docker containers. Traffic is allocated through the routing system to ensure that each instance runs independently on different machines, and data transmission between instances is achieved using message middleware.
It realizes the deployment of multiple instance data without interfering with each other, improves system stability and security, makes full use of server resources, and meets the needs of high concurrency processing.
Smart Images

Figure CN120233996A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of instance management, and in particular, to a multi-instance control method, device, and storage medium based on Node-RED. Background Art
[0002] Node-RED is an open-source visual programming tool based on Node.js. Through an intuitive graphical interface, it helps developers easily connect various hardware devices, APIs, and online services to build complex application processes. Node-RED provides a browser-based visual editor where users can define data flows by dragging and dropping different types of nodes and connecting them. Each node represents a functional unit, such as input, processing, output, etc. Users can install additional node packages via npm to extend the functionality of Node-RED. Currently, the community provides thousands of nodes covering various application scenarios. Node-RED also provides powerful debugging tools to help developers monitor data flows in real time. Through the Debug Node, users can output debugging information at any position in the process, facilitating problem troubleshooting.
[0003] However, currently Node-RED only supports single-instance deployment, which means that only one Node-RED instance can be deployed in a running environment. This deployment method may lead to uneven resource allocation and performance bottlenecks when facing complex business scenarios and high-concurrency requirements, and cannot fully utilize server resources to meet the needs of multi-task concurrent processing. Node-RED cannot perform process isolation, and all processes run in the same global namespace, resulting in interference between variables and data of different processes, increasing the complexity of process development and maintenance, and at the same time reducing the stability and security of the system. Therefore, to solve the problem that the current Node-RED only supports single-instance deployment and cannot achieve non-interfering deployment of multiple instances of data, a new technology is needed to solve the current problem. Summary of the Invention
[0004] The main purpose of the present invention is to solve the technical problem that the current Node-RED only supports single-instance deployment and cannot achieve non-interfering deployment of multiple instances of data.
[0005] The first aspect of the present invention provides a multi-instance control method based on Node-RED. The multi-instance control method based on Node-RED is applied to a multi-instance control system based on Node-RED. The multi-instance control system based on Node-RED includes: an interaction system, a routing system, and a multi-instance system. The multi-instance control method based on Node-RED includes:
[0006] The interactive system constructs a control panel based on the full-stack framework Next.js, obtains N Node-RED version information in a preset cloud database, and publishes the N Node-RED version information using the cloud database, where N is a positive integer;
[0007] Receives a user interaction instruction, creates an instance form in the control panel according to the N Node-RED version information, generates instance configuration information, and sends the instance configuration information to the routing system;
[0008] The routing system receives the instance configuration information and sends the instance configuration information to the multi-instance system;
[0009] The multi-instance system receives the instance configuration information and obtains N Node-RED version information based on the cloud database;
[0010] Based on a preset Docker API, pulls container data corresponding to the Node-RED version information of the instance configuration information from a preset Docker image database, and loads the instance configuration information according to the Node-RED components corresponding to the container data to generate a startup instance, where the interactive system monitors the running status of the startup instance through the Docker API;
[0011] When the startup instance updates the running node, the interactive system obtains the update data of the startup instance and sends the update data to the routing system;
[0012] The routing system receives the update data and adjusts the routing configuration based on the update data, so that the interactive system allocates the startup instance connected to the updated running node.
[0013] Optionally, in the first implementation manner of the first aspect of the present invention, the routing system receives the update data and adjusts the routing configuration based on the update data, so that the interactive system allocates the startup instance connected to the updated running node, including:
[0014] The routing system receives the update data based on the Nginx component;
[0015] Uses the Nginx component to adjust the routing configuration through the update data, so that the interactive system allocates the startup instance connected to the updated running node.
[0016] Optionally, in the second implementation manner of the first aspect of the present invention, after using the Nginx component to adjust the routing configuration through the update data, so that the interactive system allocates the startup instance connected to the updated running node, it further includes:
[0017] Record the updated data in the Nginx log corresponding to the Nginx component.
[0018] Optionally, in the third implementation manner of the first aspect of the present invention, the interaction system obtaining the updated data of the startup instance includes:
[0019] The interaction system obtains the updated data of the startup instance based on the Docker API.
[0020] Optionally, in the fourth implementation manner of the first aspect of the present invention, the interaction system includes: an interaction front-end subsystem and an interaction back-end subsystem. The receiving of the user interaction instruction, creating an instance form in the control panel according to the N Node-RED version information, and generating the instance configuration information includes:
[0021] The interaction front-end subsystem receives the user interaction instruction on the control panel, creates an instance form on the control panel, and sends the data corresponding to the instance form to the interaction back-end subsystem through WebSocket;
[0022] The interaction back-end subsystem receives the data corresponding to the instance form, calls the model data corresponding to the N Node-RED version information, and generates the instance configuration information.
[0023] Optionally, in the fifth implementation manner of the first aspect of the present invention, after loading the instance configuration information according to the Node-RED component corresponding to the container data and generating the startup instance, it further includes:
[0024] The interaction system assigns an instance ID identifier to the startup instance;
[0025] Based on the instance ID identifier, create an independent storage space and a database link corresponding to the startup instance.
[0026] Optionally, in the sixth implementation manner of the first aspect of the present invention, the instances in the multi-instance system transmit data to each other through a message middleware.
[0027] Optionally, in the seventh implementation manner of the first aspect of the present invention, the message middleware includes: Kafka middleware and RabbitMQ middleware.
[0028] In a second aspect of the present invention, a multi-instance control device based on Node-RED is provided, including: a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected by a line; the at least one processor invokes the instructions in the memory to enable the multi-instance control device based on Node-RED to execute the above-mentioned multi-instance control method based on Node-RED.
[0029] In a third aspect of the present invention, a computer-readable storage medium is provided, in which instructions are stored, and when it runs on a computer, it enables the computer to execute the above-mentioned multi-instance control method based on Node-RED.
[0030] In an embodiment of the present invention, a control panel is built based on the full-stack framework Next.js. The cloud database and Docker containers are used to start Node-RED instances based on different versions of the edge-side Node-RED, and the Docker API is used to operate the images and containers to ensure that the same instance is only started on one machine when deployed on multiple machines, implementing a dual-machine cold standby mechanism for the instances. The traffic is redistributed through the routing system, and the data between different instances does not interfere with each other, solving the technical problem that the current Node-RED only supports single-instance deployment and cannot achieve non-interfering deployment of multi-instance data. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 It is a schematic diagram of an embodiment of the multi-instance control method based on Node-RED in an embodiment of the present invention;
[0032] Figure 2 It is a schematic diagram of a specific embodiment of step 102 of the multi-instance control method based on Node-RED in an embodiment of the present invention;
[0033] Figure 3 It is a schematic diagram of a specific embodiment of step 107 of the multi-instance control method based on Node-RED in an embodiment of the present invention;
[0034] Figure 4 It is a network topology diagram of an embodiment of the multi-instance control method based on Node-RED in an embodiment of the present invention;
[0035] Figure 5 It is a schematic diagram of an embodiment of the multi-instance control device based on Node-RED in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0036] An embodiment of the present invention provides a multi-instance control method, device and storage medium based on Node-RED.
[0037] The embodiments disclosed by the present invention will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not used to limit the protection scope of the present invention.
[0038] In the description of the embodiments disclosed by the present invention, the term "including" and its like terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "an embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. There may also be other explicit and implicit definitions hereinafter.
[0039] For ease of understanding, the specific process of the embodiments of the present invention will be described below. Please refer to Figure 1 , an embodiment of the multi-instance control method based on Node-RED in the embodiments of the present invention. The multi-instance control method based on Node-RED is applied to a multi-instance control system based on Node-RED. The multi-instance control system based on Node-RED includes: an interaction system, a routing system, and a multi-instance system. The multi-instance control method based on Node-RED includes:
[0040] 101. The interaction system constructs a control panel based on the full-stack framework Next.js, obtains N Node-RED version information in a preset cloud database, and publishes the N Node-RED version information by using the cloud database, where N is a positive integer;
[0041] In this embodiment, the pages folder of Next.js is used to organize pages. For example, pages / instances.js is used as the instance management page, and pages / instances / [id].js is used to display the details of a single instance. State management tools such as useContext or Redux of Next.js are used to manage the state and data of the instances to ensure the consistency of the front-end and back-end data. A caching function is integrated in the control panel. Redis or a similar tool is used to cache different version information and download links of Node-RED. N Node-RED version information is obtained in a preset cloud database, and the cloud database publishes version update messages through a message queue (such as MQTT or AMQP), and edge nodes subscribe to this message queue.
[0042] 102. Receive a user interaction instruction, create an instance form in the control panel according to the N Node-RED version information, generate instance configuration information, and send the instance configuration information to the routing system;
[0043] In this embodiment, a version selection function is provided in the control panel, and the user can select the Node-RED version to be started. Receive a user interaction instruction, generate instance configuration information according to the N Node-RED version information, and send the instance configuration information to the routing system, and the routing system transmits the instance configuration information to the edge node.
[0044] Specifically, the interaction system includes: an interaction front-end subsystem, an interaction back-end subsystem, please refer to Figure 2 , Figure 2 FIG. is a schematic diagram of a specific embodiment of step 102 of the multi-instance control method based on Node-RED in the embodiment of the present invention. The following steps can be executed in step 102:
[0045] 1021. The interaction front-end subsystem receives a user interaction instruction on the control panel, creates an instance form on the control panel, and sends the data corresponding to the instance form to the interaction back-end subsystem through WebSocket;
[0046] 1022. The interaction back-end subsystem receives the data corresponding to the instance form, calls the model data corresponding to the N Node-RED version information, and generates instance configuration information.
[0047] In steps 1021-1022, the interaction front-end subsystem is used to receive a user interaction instruction on the control panel, create an instance form on the control panel, and send the data corresponding to the instance form to the interaction back-end subsystem through REST API or WebSocket. The interaction back-end subsystem calls the corresponding services and data models according to the data request content corresponding to the instance form to generate instance configuration information.
[0048] 103. The routing system receives the instance configuration information and sends the instance configuration information to the multi-instance system;
[0049] In this embodiment, the routing system receives the instance configuration information, sends the instance configuration information to the multi-instance system, and places the instance configuration information in the edge node corresponding to the multi-instance system.
[0050] 104. The multi-instance system receives the instance configuration information and obtains the N Node-RED version information based on the cloud database;
[0051] In this embodiment, the multi-instance system receives instance configuration information. The cloud publishes version update messages through a message queue (such as an MQTT component or an AMQP component), and the edge nodes subscribe to this message queue.
[0052] 105. Based on the preset Docker API, pull the container data corresponding to the Node-RED version information of the instance configuration information from the preset Docker image database, and load the instance configuration information according to the Node-RED components corresponding to the container data to generate a startup instance. Among them, the interaction system monitors the running status of the startup instance through the Docker API;
[0053] In this embodiment, after receiving the version information, the edge node pulls the Node-RED image container data corresponding to the version of the instance configuration information from the Docker image database of the cloud or the local repository through the Docker API, extracts the corresponding Node-RED components from the Node-RED image container, loads the instance configuration information, uses the Docker API to start the Node-RED instance, specifies the corresponding version image. For example, use the docker run command to activate the instance and map the corresponding ports to generate a startup instance. And the interaction system monitors the running status of the startup instance through the Docker API, such as CPU usage, memory consumption, etc.
[0054] The backend of the control panel uses the official Docker SDK (such as Dockerode) to perform operations such as pulling and deleting images, starting, stopping, or deleting containers through the SDK to achieve dynamic management of instances. When deploying on multiple machines, use a distributed lock (such as the SETNX command of Redis) to ensure that the same instance is only started on one machine. When the primary node fails, the standby node receives notifications through a message queue (such as Kafka) and automatically takes over the instance.
[0055] 106. When the startup instance updates the running node, the interaction system obtains the update data of the startup instance and sends the update data to the routing system;
[0056] In this embodiment, when the instance switches the running node, the backend of the control panel calls the middleware API to obtain the update data of the startup instance and sends the update data to the routing system.
[0057] Specifically, the following specific implementation manners are included in step 106:
[0058] 1061. The interaction system obtains the update data of the startup instance based on the Docker API.
[0059] In step 1061, the interaction system obtains the updated data of the startup instance based on the interface information of the Docker API.
[0060] 107. The routing system receives the updated data and adjusts the routing configuration based on the updated data, so that the interaction system allocates the startup instance connected to the updated running node.
[0061] In this embodiment, the routing system receives the updated data, adjusts the routing configuration based on the updated data, and distributes the interaction system requests to the new instance nodes to ensure the continuity and high availability of the service.
[0062] Specifically, please refer to Figure 3 , Figure 3 FIG. is a schematic diagram of a specific embodiment of step 107 of the multi-instance control method based on Node-RED in the embodiment of the present invention. Step 107 includes the following specific embodiments:
[0063] 1071. The routing system receives the updated data based on the Nginx component;
[0064] 1072. Using the Nginx component, adjust the routing configuration through the updated data, so that the interaction system allocates the startup instance connected to the updated running node.
[0065] In steps 1071-1072, please refer to Figure 4 , Figure 4 FIG. is an implementation network topology diagram of the multi-instance control method based on Node-RED in the embodiment of the present invention. When the instance switches the running node, the control panel backend calls the middleware API to notify Nginx to update the routing rules. According to the new routing configuration, Nginx distributes the client requests to the new instance nodes to ensure the continuity and high availability of the service.
[0066] Further, after step 1072, the following specific embodiments are also included:
[0067] 10721. Record the updated data in the Nginx log corresponding to the Nginx component.
[0068] In step 10721, in the Nginx configuration file, use the log_format directive to define the log format. For example:
[0069] log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
[0070] '$status$body_bytes_sent"$http_referer" '
[0071] '"$http_user_agent""$http_x_forwarded_for"';
[0072] It can record information such as the IP address, request time, request method, response status code, and response body size when the client sends updated data.
[0073] Specifically, after step 107, the following specific implementation manners are further included:
[0074] 1073. The interaction system assigns an instance ID identifier to the startup instance;
[0075] 1074. Based on the instance ID identifier, an independent storage space and a database link corresponding to the startup instance are created.
[0076] In steps 1073-1074, an instance ID identifier is assigned to each startup instance in the interaction system. Based on the instance ID identifier, a MongoDB or MySQL database is used to create an independent database or table space for each instance, and a corresponding database connection is created.
[0077] In a specific embodiment, the instances in the multi-instance system transmit data to each other through a message middleware. The message middleware includes: Kafka middleware, RabbitMQ middleware. Kafka or RabbitMQ message middleware is used to realize data sharing and interaction between different instances. The Message Queue node is used in the Node-RED process to send and receive cross-instance messages, realize information transmission between multiple instances, and the data between instances will not interfere with each other.
[0078] In the embodiment of the present invention, a control panel is built based on the full-stack framework Next.js. Using a cloud database and Docker containers, Node-RED instances are started based on different versions of edge Node-RED, and the mirror and container are operated based on the Docker API to ensure that the same instance is only started on one machine when deployed on multiple machines, realizing the dual-machine cold standby mechanism of the instance. The traffic is redistributed through the routing system, and the data between different instances does not interfere with each other, solving the technical problem that the current Node-RED only supports single-instance deployment and cannot realize non-interfering deployment of multi-instance data.
[0079] Figure 5FIG. 0 is a schematic structural diagram of a multi-instance control device based on Node-RED provided by an embodiment of the present invention. The multi-instance control device 500 based on Node-RED may vary greatly due to configuration or performance differences, and may include one or more central processing units (CPUs) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 for storing application programs 533 or data 532 (for example, one or more mass storage devices). Among them, the memory 520 and the storage media 530 may be transient storage or persistent storage. The program stored in the storage media 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the multi-instance control device 500 based on Node-RED. Further, the processor 510 may be configured to communicate with the storage media 530 and execute a series of instruction operations in the storage media 530 on the multi-instance control device 500 based on Node-RED.
[0080] The multi-instance control device 500 based on Node-RED may further include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input / output interfaces 560, and / or one or more operating systems 531, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art can understand that Figure 5 The shown structural diagram of the multi-instance control device based on Node-RED does not constitute a limitation on the multi-instance control device based on Node-RED, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0081] The present invention also provides a computer-readable storage medium. The computer-readable storage medium may be a non-volatile computer-readable storage medium, and may also be a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are run on a computer, the computer is caused to execute the steps of the multi-instance control method based on Node-RED.
[0082] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0083] Moreover, although the operations are depicted in a particular order, this should be understood as requiring that such operations be performed in the particular order shown or in sequential order, or that all illustrated operations be performed to achieve the desired result. In certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the present disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single implementation. Conversely, various features that are described in the context of a single implementation can also be implemented separately or in any suitable sub-combination in multiple implementations.
[0084] Although the subject matter has been described in language specific to structural features and / or methodological acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.
Claims
1. A multi-instance control method based on Node-RED, characterized in that: The multi-instance control method based on Node-RED is applied to a multi-instance control system based on Node-RED. The multi-instance control system based on Node-RED includes: an interactive system, a routing system, and a multi-instance system. The multi-instance control method based on Node-RED includes: The interactive system builds a control panel based on the full-stack framework Next.js, obtains N Node-RED version information in a preset cloud database, and publishes N Node-RED version information using the cloud database, where N is a positive integer; Receiving a user interaction instruction, creating an instance form in the control panel according to the N Node-RED version information, generating instance configuration information, and sending the instance configuration information to the routing system; The routing system receives the instance configuration information and sends the instance configuration information to the multi-instance system; The multi-instance system receives the instance configuration information, and obtains N Node-RED version information based on the cloud database; Based on a preset Docker API, container data of the Node-RED version information corresponding to the instance configuration information is pulled from a preset Docker image database, and the instance configuration information is loaded according to the Node-RED component corresponding to the container data to generate a startup instance, wherein the interactive system monitors the running status of the startup instance through the Docker API; When the startup instance updates the running node, the interactive system obtains the update data of the startup instance and sends the update data to the routing system; The routing system receives the update data and adjusts the routing configuration based on the update data so that the interactive system allocates the startup instance connected to the updated execution node.
2. The multi-instance control method based on Node-RED according to claim 1, characterized in that: The routing system receives the update data, and based on the update data, adjusts the routing configuration so that the interactive system allocates the startup instance connected to the update running node, including: The routing system receives the update data based on the Nginx component; The Nginx component is used to adjust the routing configuration through the update data so that the interactive system allocates the startup instance connected to the update running node.
3. The multi-instance control method based on Node-RED according to claim 2 is characterized in that: After the Nginx component is used to adjust the routing configuration through the update data so that the interactive system allocates the startup instance connected to the updated running node, the method further includes: The update data is recorded in the Nginx log corresponding to the Nginx component.
4. The multi-instance control method based on Node-RED according to claim 1, characterized in that: The interactive system acquiring the update data of the startup instance includes: The interactive system obtains update data of the startup instance based on the Docker API.
5. The multi-instance control method based on Node-RED according to claim 1, characterized in that: The interactive system includes: an interactive front-end subsystem and an interactive back-end subsystem. The receiving of user interactive instructions, creating an instance form in the control panel according to the N Node-RED version information, and generating instance configuration information include: The interactive front-end subsystem receives a user interaction instruction on the control panel, creates an instance form on the control panel, and sends data corresponding to the instance form to the interactive back-end subsystem via WebSocket; The interactive backend subsystem receives the data corresponding to the instance form, calls the model data corresponding to the N Node-RED version information, and generates instance configuration information.
6. The multi-instance control method based on Node-RED according to claim 1, characterized in that: After the Node-RED component corresponding to the container data loads the instance configuration information and generates a startup instance, the method further includes: The interactive system assigns an instance ID to the startup instance; Based on the instance ID, an independent storage space and a database link corresponding to the started instance are created.
7. The multi-instance control method based on Node-RED according to claim 1, characterized in that: The instances in the multi-instance system transmit data to each other through message middleware.
8. The multi-instance control method based on Node-RED according to claim 7, characterized in that: The message middleware includes: Kafka middleware and RabbitMQ middleware.
9. A multi-instance control device based on Node-RED, characterized in that: The Node-RED-based multi-instance control device comprises: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor calls the instruction in the memory to enable the Node-RED-based multi-instance control device to execute the Node-RED-based multi-instance control method according to any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the multi-instance control method based on Node-RED is implemented as described in any one of claims 1 to 8.