Mastering Liteflow: A Lightweight Rule Engine for Spring Boot
This article introduces Liteflow, a lightweight yet powerful rule engine for Spring Boot, covering its architecture, supported rule formats, component types, EL rule file syntax, data context handling, configuration options, and a real‑world e‑commerce workflow example that demonstrates parallel and sequential processing.
1 Introduction
In daily development, serial or parallel business processes often lack correlation, and using strategy and template patterns can solve this, but many files become cumbersome. Introducing a rule engine from a global perspective addresses this issue.
2 Liteflow Rule Engine
liteflowis a lightweight yet 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 engine’s overall architecture is shown above. It parses rule files, registers components, and assembles information at startup for high performance.
3 How to Use Liteflow
Usage starts by obtaining a data context, parsing the corresponding rule file, and executing a chain via the flowExecutor. Each chain contains business nodes that can be written in various script languages (Groovy, JS, Python, Lua).
Dependency (Maven):
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.10.6</version>
</dependency>3.1 Components
Ordinary Component : Implement NodeComponent, override process, optionally iaAccess, isContinueOnError, isEnd.
Switch Component : Extend NodeSwitchComponent and implement processSwitch to return the next node name.
Condition Component : Extend NodeIfComponent and override processIf to return a boolean result.
3.2 EL Rule Files
Rule files are typically written in XML. Examples:
# 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);3.3 Data Context
The data context carries parameters between nodes. Execution example:
LiteflowResponse response = flowExecutor.execute2Resp(
"chain1", initialParams, CustomContext.class);3.4 Parameter Configuration
Typical application.yml 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: true4 Business Practice
Example: In 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>Images illustrate the execution flow and node processing.
5 Summary
Most of Liteflow’s work—rule parsing, component registration, and assembly—occurs at startup, giving it high execution performance and detailed timing statistics. This article introduced Liteflow’s core concepts and practical usage.
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.
