Master Liteflow: A Lightweight Rule Engine for Complex Business Flows
This article introduces the Liteflow rule engine, explains its architecture, component types, EL rule syntax, data context handling, Spring Boot configuration, and demonstrates a real‑world e‑commerce order processing scenario with code examples and diagrams.
1. Introduction
In many projects, serial or parallel business processes need to be orchestrated without tight coupling. Traditional strategy/template patterns lead to scattered files, making the overall flow hard to grasp. Liteflow provides a lightweight yet powerful rule engine that solves this problem from a global perspective.
2. Liteflow Rule Engine Overview
Liteflow is a plug‑and‑play rule engine that can quickly compose complex rule chains. It supports multiple rule file formats (XML, JSON, YAML) and various storage backends such as SQL, Zookeeper, Nacos, Apollo.
3. Component Types
Components correspond to nodes in the rule file. The main types are:
Ordinary Component – implements NodeComponent, used in when and then logic. Override process, iaAccess, isContinueOnError, isEnd as needed.
Switch Component – extends NodeSwitchComponent and implements processSwitch to decide the next node, similar to a Java switch.
If Component – extends NodeIfComponent and overrides processIf to return a boolean result.
3.1 Component Code Example
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.10.6</version>
</dependency>3.2 EL Rule File Syntax (XML)
# Serial execution
THEN(a, b, c, d);
# Parallel execution
WHEN(a, b, c);
# Nested serial & parallel
THEN(a, WHEN(b, c, d), e);
# Switch
SWITCH(a).to(b, c, d);
# Conditional
THEN(IF(x, a), b);3.3 Data Context
The data context carries parameters between nodes. It is passed as a class type when executing a chain.
LiteflowResponse response = flowExecutor.execute2Resp(
"chain1",
initParam,
CustomContext.class
);3.4 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 Example
The article demonstrates an e‑commerce scenario where, after an order is completed, points are awarded, a message is sent, and SMS and email are dispatched in parallel.
The corresponding rule file (test_flow.el.xml) looks like:
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="test_flow">
THEN(
prepareTrade,
grantScore,
sendMq,
WHEN(sendEmail, sendPhone)
);
</chain>
</flow>Before executing the flow, input parameters are transformed into a custom context object for easy parameter passing.
During node execution (e.g., points grant), the context is accessed and business logic is performed. The isAccess method can be overridden to decide whether the node should run.
5. Summary
Most of Liteflow’s work—rule parsing, component registration, and assembly—occurs at startup, giving it high execution performance. It can log execution time for each business step and provide statistics. This article covered Liteflow’s core concepts, component implementation, rule syntax, configuration, and a practical e‑commerce use case.
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.
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.
