Introducing Liteflow: A Lightweight Rule Engine for Java Backend Development
This article introduces Liteflow, a lightweight yet powerful Java rule engine built on Spring Boot, explains its architecture, usage patterns, component types, EL rule files, data context handling, configuration options, and demonstrates a real‑world e‑commerce workflow, while also containing promotional material for related services.
In daily development, serial or parallel business processes often lack clear relationships; using a combination of strategy and template patterns can solve this, but coding leads to many files. Introducing a rule engine, liteflow, addresses these challenges from a global perspective.
Liteflow Overview liteflow is a lightweight, powerful rule engine that works out‑of‑the‑box, enabling complex rule orchestration quickly. It supports multiple rule file formats (XML/JSON/YAML) and storage options (SQL, Zookeeper, Nacos, Apollo). The official site is https://liteflow.yomahub.com .
Dependency example:
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.10.6</version>
</dependency>Component Types
Ordinary Component : Implement NodeComponent, used in when and then logic. Override iaAccess, isContinueOnError, and isEnd as needed.
Switch Component : Extends NodeSwitchComponent and overrides processSwitch to choose the next node, similar to a Java switch.
Condition Component : Extends NodeIfComponent and overrides processIf to return true/false and direct flow.
EL Rule Files
Rules are written in XML (or other supported formats). 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
The data context carries parameters between nodes. Execution example:
LiteflowResponse response = flowExecutor.execute2Resp("chain1", initialParams, CustomContext.class);Parameter Configuration
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: trueBusiness Practice Example
An e‑commerce scenario where, after an order is completed, points are granted, a message is sent, and SMS and email are dispatched in parallel. The flow definition:
<flow>
<chain name="test_flow">
THEN(
prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
);
</chain>
</flow>The article also notes that most of Liteflow’s work (rule parsing, component registration) happens at startup, providing high performance and detailed execution metrics.
Summary
Liteflow’s core concepts and usage have been introduced, covering architecture, component development, rule file syntax, data context, configuration, and a practical e‑commerce workflow example.
Additionally, the article contains promotional sections advertising ChatGPT services, a paid “knowledge planet” community, and various marketing links.
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.
