Dynamic Components
# Overview of Dynamic Components
In addition to native components (nc), RuleGo rule chains can also implement dynamic components (dc) through JSON DSL. Dynamic components are essentially sub-rule chains that combine and orchestrate existing components to create a new component for use in rule chains.
The characteristics of dynamic components are:
- Components can be dynamically installed, upgraded, and uninstalled.
- Components are defined through JSON DSL, eliminating the need for compilation, which facilitates publishing and upgrading.
- Sub-rule chains can be converted into components.
- They provide secondary encapsulation and extension of existing components.
- Components can be installed and updated online through component marketplace (opens new window) .
# Implementation of Dynamic Components
Dynamic components can be implemented through the following steps:
# 1. Define Components through Sub-Rule Chain DSL
Example:
{
"ruleChain": {
"id": "dataTransform", // Component type identifier
"name": "Temperature Conversion",// Component name
"root": false,// Defined as a sub-rule chain
"additionalInfo": { // Component metadata
"category": "custom", // Component category
"icon": "custom-node", // Component icon
"description": "Temperature conversion component", // Component description
"relationTypes": ["Success"], // Allowed relationship types with the next component
"author": "admin",
"version": "1.0.0",
"inputSchema": { // Parameter configuration definition (JSON Schema)
"type": "object",
"properties": { // Component parameter definition
"scaleFactor": {
"type": "number",// Parameter type (supports number, string, bool, object, array)
"title": "Conversion Factor",// Title
"default": 1.8 // Default value
}
}
}
}
},
"metadata": { // Component logic implementation
"nodes": [
{
"type": "jsTransform",
"configuration": {
"jsScript": "msg.temperature = msg.temperature * ${vars.scaleFactor} + 32; return {'msg':msg,'metadata':metadata,'msgType':msgType};" // Reference component parameters through ${vars.fieldName}
}
}],
"connections": []
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
The dynamic component DSL is consistent with the Rule Chain DSL. Among them:
ruleChain.id
: The component type identifier, used to uniquely identify the component type. Rule chains use this identifier to utilize the component. Component type identifiers can be defined using a namespace format, for example: x/dataTransformruleChain.additionalInfo
describes the component's metadata, including its category, icon, description, relationship types, and input parameter configuration.
additionalInfo Object
Field Name | Type | Required | Description | Default Value |
---|---|---|---|---|
category | String | No | Component category, helps users quickly locate the required component type. | custom |
icon | String | No | Component icon, displayed on the user interface, usually a class name or path of the icon. | custom-node |
description | String | No | Component description, a brief explanation of the component's functionality to help users understand its purpose. | |
relationTypes | Array | No | Allowed relationship types with the next component. | ["Success","Failure"] |
author | String | No | Author. | |
version | String | No | Version. | |
inputSchema | JSON Schema | No | Component parameter configuration definition, defines the structure of the component's input parameters, follows the JSON Schema format, specifies parameter types, titles, default values, etc. | See the inputSchema table |
inputSchema: If the component parameter configuration does not exist, the system automatically generates it by scanning ${vars.fieldName}
.
inputSchema Object
Field Name | Type | Required | Description | Example Value |
---|---|---|---|---|
type | String | Yes | Parameter type, specifies the parameter type, supports number, string, bool, object, array, etc. | "number" |
properties | Object | No | Parameter properties, defines the specific attributes of each parameter. | See the properties table |
properties Object
Field Name | Type | Required | Description | Example Value |
---|---|---|---|---|
type | String | No | Parameter type, specifies the type of this parameter. | "number" |
title | String | No | Parameter title, the display name of the parameter. | "Conversion Factor" |
default | Number | No | Parameter default value, the default value of the parameter. | 1.8 |
# 2. Implement Component Logic through Orchestration and Combination of Existing Components:
Implement component logic by combining and orchestrating existing components through metadata.nodes
and metadata.connections
(the same as implementing rule chain logic).
# 3. Register the Component DSL with the Engine:
// Define a component through DSL:
// componentType: Component type identifier, used to uniquely identify the component type. Rule chains use this identifier to utilize the component.
// dsl: Component DSL
dynamicNode := NewDynamicNode(componentType, dsl)
Registry.Register(dynamicNode)
2
3
4
5
# 4. Use the Component in Rule Chains:
{
"ruleChain": {
"id": "9ehrY6tXl3y6",
"name": "Test Dynamic Component",
"debugMode": false,
"root": false,
"disabled": false,
"additionalInfo": {
"createTime": "2025/03/26 15:42:39",
"layoutX": "280",
"layoutY": "280",
"updateTime": "2025/03/26 15:42:39",
"username": "admin"
}
},
"metadata": {
"endpoints": [],
"nodes": [
{
"id": "node_2",
"additionalInfo": {
"layoutX": 610,
"layoutY": 250
},
"type": "dataTransform",
"name": "Convert Temperature",
"debugMode": false,
"configuration": {
"scaleFactor": 1.8
}
},
{
"id": "node_4",
"additionalInfo": {
"layoutX": 920,
"layoutY": 260
},
"type": "log",
"name": "Print Log",
"debugMode": false,
"configuration": {
"jsScript": "return 'Incoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"
}
}
],
"connections": [
{
"fromId": "node_2",
"toId": "node_4",
"type": "Success"
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54