Liteflow Rule Engine: Architecture, Components, Configuration and Practical Business Use
This article introduces the Liteflow rule engine, explains its architecture and components, demonstrates how to configure and use it with Spring Boot, shows EL rule file examples and a real e‑commerce workflow, and summarizes its performance benefits for backend development.
1. Introduction
In daily development, serial or parallel business processes often need to be orchestrated without strong coupling. Combining strategy and template patterns can solve this, but coding leads to many files. A rule engine from a global perspective simplifies the problem; the protagonist is liteflow .
2. Liteflow Rule Engine Overview
liteflow is a lightweight yet powerful rule engine that works out‑of‑the‑box, allowing complex rule orchestration to be built quickly. It supports multiple rule file formats (XML/JSON/YAML) and storage options (SQL, Zookeeper, Nacos, Apollo, etc.).
Architecture diagram:
3. How to Use Liteflow
The usage starts by obtaining a context, parsing the rule file, and executing the chain via the executor. Each chain contains business nodes (components) that can be written in various scripting languages (Groovy, JS, Python, Lua).
Official website and Maven dependency:
https://liteflow.yomahub.com
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.10.6</version>
</dependency>Example of a complex flow supported by liteflow :
Hot deployment is also supported; modifying rule files takes effect immediately.
3.1 Components
Components correspond to nodes in the rule file. Types include:
Ordinary Component : Extend NodeComponent , implement process , optionally override iaAccess , isContinueOnError , isEnd .
Switch Component : Extend NodeSwitchComponent and implement processSwitch to decide the next node (similar to Java switch ).
If Component : Extend NodeIfComponent and implement processIf to return true/false and choose a branch.
Other advanced components (loop, iteration, exit) exist but are often replaced by ordinary components for simplicity.
3.2 EL Rule Files
Rule files are usually written in XML. Examples:
# Serial composition, then represents sequential execution, when represents parallel execution
THEN(a, b, c, d);
# Parallel composition
WHEN(a, b, c);
# Nested serial and parallel
THEN(a, WHEN(b, c, d), e);
# Switch composition
SWITCH(a).to(b, c, d);
# Conditional composition
THEN(IF(x, a), b);3.3 Data Context
The data context is crucial for passing parameters between nodes. Example execution:
LiteflowResponse response = flowExecutor.execute2Resp(
"chain1",
initialParams,
CustomContext.class
);3.4 Parameter Configuration
Typical Spring Boot configuration (application.yml):
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: true4. Business Practice
Using an e‑commerce scenario: after an order is completed, the flow grants points, sends messages, and concurrently sends SMS and email.
<flow>
<chain name="test_flow">
THEN(
prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
);
</chain>
</flow>Execution involves converting input parameters into a context object, then invoking the defined chain.
5. Summary
Most of liteflow 's work—rule parsing, component registration, and assembly—is done at startup, giving it high execution performance. The article covered the core concepts, component types, EL rule files, data context, configuration, and a practical e‑commerce example.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.