Skip to main content

Rule Engine

The rule engine supports visual flow orchestration, configuring data processing flows by dragging nodes to implement complex data processing logic. The rule engine adopts an event-driven mode, automatically triggering flow processing when node input data changes.

Core Concepts

Data Flow Mechanism

The rule engine adopts an event-driven data flow mechanism:

  1. Output triggers propagation: When a node's output property is set, all downstream nodes connected to that output are automatically triggered
  2. Automatic propagation: Data changes automatically propagate along the node connection chain until all related nodes have completed processing
  3. Debounce optimization: Uses an intelligent scheduler to prevent high-frequency triggering, ensuring only the last execution runs during rapid changes

Node Lifecycle

Each node instance has a complete lifecycle:

Lifecycle PhaseMethodDescription
InitializationInitAsync()Called once when the node is created, used to initialize internal state
ExecutionChangedAsync()Triggered when input parameters change, executes the node's business logic
Output callbackOutputChangedCallbackTriggered when an output property is set, notifies downstream nodes

Execution Flow

Complete execution flow of the rule engine

Security Mechanisms

The rule engine has built-in multiple security protections:

1. Circular Dependency Detection

Automatically detects whether node connections have cycles when the flow starts:

  • Uses depth-first search (DFS) algorithm to detect cycles in the graph
  • Logs a warning when circular dependencies are detected
  • Prevents infinite loops caused by flow design errors

2. Execution Count Limit

Each node has a maximum execution count limit (default 100 times):

  • Per single propagation chain: The counter is reset each time triggered from the starting node
  • Prevents accidental loops: Automatically stops after exceeding 100 times in a single propagation chain
  • Does not affect normal usage: Multiple triggers at different time points are not cumulative
  • Automatically stops propagation and logs an error when the limit is exceeded
  • The limit can be adjusted via FlowExecutionContext.MaxExecutionCount

Example Explanation:

Timeline:
T1: Temperature sensor triggers → [Temperature processing] executes 1 time → counter=1
T2: Temperature sensor triggers → [Temperature processing] executes 1 time → counter=1 (after reset)
T3: Temperature sensor triggers → [Temperature processing] executes 1 time → counter=1 (after reset)

Circular dependency scenario:
Single trigger: [NodeA]→[NodeB]→[NodeC]→[NodeA]→[NodeB]→...
execute 1 execute 2 execute 3 execute 4 execute 5...
Stops when a node exceeds 100 executions

3. Debounce Mechanism

Uses an intelligent scheduler to prevent high-frequency triggering:

  • Only the last execution runs during multiple triggers in a short period
  • Avoids repeated calculations caused by rapid data changes
  • Improves system performance and stability

Feature Entry

Click "Rule Engine" in the left menu to enter the management page.

Rule engine page

Flow List

ColumnDescription
Flow NameIdentifier name of the rule flow
DescriptionFlow description information
VersionFlow version number
StatusEnabled/Disabled status
NoDebounceWhether debounce is disabled, debounce is enabled by default

Operation Functions

FunctionDescription
New FlowCreate a new rule flow
DetailsOpen the flow editor
Enable/DisableToggle flow enabled status
DeleteDelete the flow
RefreshRefresh the flow list

Flow Editor

Click the "Details" button to enter the flow editor:

Flow editor page

Toolbar Functions

FunctionDescription
Flow NameEdit the flow name
Flow DescriptionEdit the flow description
ExportExport flow configuration as JSON file
ImportImport flow configuration from JSON file
Export ExcelExport rule flow to Excel file
Import ExcelImport rule flow from Excel file, option to clear existing flow
Auto LayoutAutomatically arrange flow nodes
Delete SelectedDelete selected nodes
SaveSave current flow configuration

Editor Layout

AreaDescription
LeftNode panel, displays available node types
CenterCanvas area, drag nodes for flow orchestration
RightProperties panel, configure parameters of selected nodes

Left Node Panel

FunctionDescription
Node SearchSearch nodes by name
Category FilterFilter nodes by category
Group CollapseNodes are grouped by category, can be collapsed/expanded

Center Canvas Area

FunctionDescription
Drag NodeDrag nodes from the left panel to the canvas
Connect NodesDrag node ports to connect to another node
Delete NodeSelect a node and press Delete key to delete
MinimapThumbnail of the canvas in the lower right corner for navigation
Node Hover TooltipHover to display real-time parameter values of the node (after the flow is enabled)

Flow editor - node connection and hover tooltip illustration

Right Properties Panel

FunctionDescription
Node NameEdit node display name
Node TypeDisplay node type (read-only)
Real-time Parameter ValuesDisplay real-time parameter values of the node after the flow is enabled
Input ParametersConfigure initial values of node input parameters
Output ParametersDisplay node output parameters
Input/Output ParametersConfigure input/output parameters

Flow Debounce Configuration

Each rule flow can be configured whether to enable the debounce mechanism:

ConfigurationDescription
NoDebounceWhether to disable debounce. Debounce is enabled by default, only the last execution runs during multiple triggers in a short period; when disabled, every trigger will execute
Tip
  • By default, the rule engine uses debounce mechanism to prevent high-frequency triggering
  • For scenarios where every trigger needs to execute (such as counters, accumulators), set NoDebounce to true
  • Disabling debounce may increase system load during high-frequency triggering, use with caution

Node Types

TypeDescription
Input NodeData input source
Processing NodeData processing logic
Output NodeData output target
Custom NodeUser-defined processing node

Node Parameter Types

Each node can define three types of parameters:

Parameter TypeAttributeDescriptionData Flow Direction
Input Parameter[ExpressionInput]Input data of the nodeReceives from upstream nodes or configures initial values
Output Parameter[ExpressionOutput]Output data of the nodeAutomatically triggers downstream nodes when changed
Input/Output Parameter[ExpressionInOut]Both input and outputCan receive upstream data, and triggers downstream when changed
Parameter Characteristics
  • Input Parameter: Can only receive data from upstream nodes, will not trigger downstream nodes
  • Output Parameter: Can only output data, automatically triggers all connected downstream nodes when changed
  • Input/Output Parameter: Has both input and output characteristics, suitable for parameters that need to be modified during processing

Data Propagation Examples

Simple Flow Example

The following is a simple temperature unit conversion flow:

[Temperature Input] → [Celsius to Fahrenheit] → [Result Output]
(25°C) (Formula calculation) (77°F)

Execution Process:

  1. Initialization Phase:

    • Create all node instances
    • Call each node's InitAsync() method
  2. First Execution:

    • Temperature input node executes ChangedAsync(), output value set to 25
    • Output change triggers the downstream "Celsius to Fahrenheit" node
    • The "Celsius to Fahrenheit" node's input parameter receives 25
    • Executes ChangedAsync(), calculates result 77
    • Output change triggers the "Result Output" node
  3. Subsequent Changes:

    • When the temperature input changes to 30
    • Automatically triggers the entire chain to re-execute
    • Final output updates to 86

Branch Flow Example

One output can connect to multiple downstream nodes to achieve data distribution:

┌→ [Alarm Judgment] → [Alarm Output]
[Temperature Sensor] → [Temperature Processing] ┤
└→ [Data Logging] → [Database Write]

Execution Process:

  1. Temperature sensor data changes
  2. Triggers the temperature processing node
  3. The output of the temperature processing node simultaneously triggers two downstream nodes:
    • Alarm judgment node
    • Data logging node
  4. Both branches execute in parallel without blocking each other

Merge Flow Example

Multiple upstream outputs can connect to different input parameters of the same downstream node:

[Temperature Sensor] → [Temperature Processing] ┐
├→ [Comprehensive Judgment] → [Result Output]
[Humidity Sensor] → [Humidity Processing] ┘

Execution Process:

  1. When either temperature or humidity changes, the "Comprehensive Judgment" node is triggered
  2. The "Comprehensive Judgment" node simultaneously receives two input parameters
  3. Makes a judgment based on the comprehensive situation of both parameters

Circular Dependency Example

Dangerous Operation

The following example demonstrates circular dependency, such designs should be avoided in actual use!

[Node A] → [Node B] → [Node C]
↑ ↓
└───────────────────┘

System Protection Mechanism:

  1. Startup Detection: Automatically detects circular dependency when the flow starts
  2. Log Warning: Records "circular dependency detected" in the log
  3. Execution Limit: Each node automatically stops after a maximum of 100 executions in a single propagation chain
  4. Error Log: Logs an error and stops propagation when the limit is exceeded

Execution Process Example:

Trigger start node → Node A executes (1st time) → Node B executes (1st time) → Node C executes (1st time)
→ Node A executes (2nd time) → Node B executes (2nd time) → Node C executes (2nd time)
→ ... (loop continues)
→ Node A executes (101st time) → ❌ Exceeds limit, stops propagation

Correct Approach: Avoid designing flows with circular dependencies, use conditional nodes or state machines instead.

Flow Management

Enable/Disable Flow

  • Enable Flow: The flow starts executing immediately after being enabled, nodes enter running state
  • Disable Flow: Stops flow execution, releases all node resources
Note

After modifying the flow configuration, the system will automatically restart the flow, and all nodes will be reinitialized. The system will:

  1. Stop the current flow execution
  2. Reload the flow configuration
  3. Re-detect circular dependencies
  4. Reinitialize all nodes
  5. Reset the execution counter (automatically resets at the start of each trigger chain)

Flow Logs

Each flow has an independent log file, recording node execution status and exception information:

  • Log path: Logs/RuleEngine/{FlowName}.db
  • Log level: Info for routine operation / Trace for temporary troubleshooting
  • Supports log query and export

Log Content Includes:

  • Flow start/stop events
  • Circular dependency detection results
  • Node execution count limit exceeded warnings
  • Node execution exception information
  • Data propagation path tracing