Liteflow Rule Engine: Concepts, Configuration, and Practical Usage in Java Backend Projects
This article introduces the Liteflow rule engine, explains its architecture and configuration, demonstrates how to define components and EL rule files, and shows a real e‑commerce workflow example, while also providing Maven dependency snippets and usage guidelines for Java Spring Boot applications.
In daily development, serial or parallel business processes often arise without direct correlation, and combining strategy and template patterns can solve these issues, though code can become scattered. This article presents Liteflow, a lightweight yet powerful rule engine that addresses such problems from a global perspective.
Liteflow is a lightweight, powerful rule engine that works out‑of‑the‑box, allowing complex rule orchestration quickly. It supports multiple rule file formats (XML/JSON/YAML) and storage options (SQL, Zookeeper, Nacos, Apollo, etc.). The overall architecture is shown in the diagram below.
Using Liteflow starts with obtaining a context, parsing rule files, and executing chains via the FlowExecutor. Each chain consists of business nodes (components) that can be implemented in various scripting languages such as Groovy, JavaScript, Python, or Lua. The official website and Maven dependency are as follows:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.10.6</version>
</dependency>Liteflow supports complex flows, illustrated by the following XML example:
<flow>
<chain name="test_flow">
THEN(prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone));
</chain>
</flow>The engine also offers hot‑deployment, allowing rule files to be modified and take effect in real time.
Component types include:
Ordinary Component : Implements NodeComponent , used in when and then logic, with methods like isAccess , isContinueOnError , and isEnd .
Switch Component : Extends NodeSwitchComponent and overrides processSwitch to decide the next node, similar to a Java switch .
If Component : Extends NodeIfComponent and overrides processIf to return a boolean result.
EL rule files are typically written in XML, with examples of serial, parallel, nested, switch, and conditional compositions:
# 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 in Liteflow; it carries parameters between nodes. Execution can be performed as follows:
LiteflowResponse response = flowExecutor.execute2Resp(
"chain1",
initialParams,
CustomContext.class
);Configuration items include rule file locations, retry counts, thread pool settings, request‑ID generators, and hot‑deployment options, as shown in the YAML snippet below:
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: trueIn a practical e‑commerce scenario, after an order is completed, Liteflow can orchestrate points issuance, message sending, and parallel SMS/email notifications using the defined flow.
The article concludes that most of Liteflow’s work—rule parsing, component registration, and assembly—is done at startup, offering high performance and detailed execution metrics.
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.