Introducing LiteFlow: A Lightweight Rule Engine for Complex Workflow Orchestration
This article introduces LiteFlow, a lightweight yet powerful rule engine that enables rapid development of complex workflow orchestration through XML/JSON/YAML rule files, supports various component types, data context handling, and hot‑deployment, and provides a complete Spring Boot integration example.
LiteFlow is a lightweight and powerful rule engine that can be used out‑of‑the‑box to quickly compose complex rule orchestration, supporting rule files in XML, JSON, or YAML and storage options such as SQL, Zookeeper, Nacos, or Apollo.
The engine’s overall architecture is shown in the diagram below, illustrating how it parses rule files, builds execution chains, and runs node components written in multiple scripting languages (Groovy, JavaScript, Python, Lua, etc.).
LiteFlow supports various component types:
Ordinary components – implement NodeComponent, used in when and then logic, with methods like process, iaAccess, isContinueOnError, and isEnd.
Switch components – extend NodeSwitchComponent and override processSwitch to decide the next node, similar to a Java switch.
Condition components – extend NodeIfComponent and implement processIf to return a boolean result.
Rule files are written in EL syntax. Example snippets:
# Serial composition
THEN(a, b, c, d);
# Parallel composition
WHEN(a, b, c);
# Nested composition
THEN(a, WHEN(b, c, d), e);
# Switch composition
SWITCH(a).to(b, c, d);
# Conditional composition
THEN(IF(x, a), b);Data context is crucial for passing parameters between nodes. Execution typically looks like:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", initialParams, CustomContext.class);Configuration in application.yml includes rule file locations, retry counts, logging, monitoring, request‑ID generator, thread pool sizes, and hot‑deployment settings:
liteflow:
ruleSource: liteflow/*.el.xml
retry-count: 0
print-execution-log: true
monitor:
enable-log: true
period: 300000
request-id-generator-class: com.platform.orderserver.config.AppRequestIdGenerator
slot-size: 10240
main-executor-works: 64
when-max-wait-seconds: 15
when-max-workers: 16
when-queue-limit: 5120
parse-on-start: true
enable: trueA practical e‑commerce scenario demonstrates LiteFlow: after an order is completed, the flow grants points, sends a message, and concurrently sends SMS and email. The XML flow definition looks like:
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="test_flow">
THEN(prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone));
</chain>
</flow>During execution, the initial parameters are transformed into a context object, enabling each node to access and modify data, such as awarding points, while the engine logs execution time and statistics.
In summary, most of LiteFlow’s work—rule parsing, component registration, and chain assembly—occurs at startup, delivering high performance and detailed monitoring; the full source code is available on GitHub.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
