Mastering Liteflow: Build Scalable Rule Engines in Java
This article introduces the lightweight Java rule engine liteflow, explains its architecture, shows how to configure and use its components, EL rule files, data context, and demonstrates a real‑world e‑commerce flow for granting points and sending notifications.
1 Introduction
During development, serial or parallel business processes often have no correlation. Traditional strategy/template coding creates many files, making it hard to see the overall flow. A rule engine from a global perspective can solve this problem, which is the focus of this article.
2 liteflow Rule Engine
liteflow is a lightweight yet powerful rule engine that works out‑of‑the‑box and can orchestrate complex rules quickly. It supports multiple rule file formats such as XML, JSON, YAML and storage options like SQL, Zookeeper, Nacos, Apollo.
liteflow can also handle hot‑deployment, allowing rule files to be updated in real time.
3 How to Use liteflow
3.1 Components
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.
Condition Component – extends NodeIfComponent and overrides processIf to return a boolean result.
3.2 EL Rule Files
Rule files can be written in XML using the following expressions:
# Serial execution
THEN(a, b, c, d);
# Parallel execution
WHEN(a, b, c);
# Nested serial and 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 to the executor:
LiteflowResponse response = flowExecutor.execute2Resp(
"chain1",
initialParams,
CustomContext.class
);3.4 Parameter Configuration
Typical liteflow configuration (application.yml) includes rule source location, retry count, thread‑pool settings, and monitoring options:
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: after an order is completed, the flow grants points, sends a message, and concurrently sends email and SMS.
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="test_flow">
THEN(
prepareTrade,
grantScore,
sendMq,
WHEN(sendEmail, sendPhone)
);
</chain>
</flow>Images illustrate the execution steps and context handling.
5 Summary
Most of liteflow’s work—rule parsing, component registration, and assembly—is performed at startup, giving it high execution performance. It can also log each node’s duration and statistics. This article introduced liteflow’s core concepts and demonstrated how to configure and use it in a Spring Boot environment.
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.
