Backend Development 12 min read

Liteflow Rule Engine: Concepts, Usage, and Business Practice

This article introduces the Liteflow rule engine, explains its architecture and supported file formats, demonstrates how to configure and use its components—including ordinary, switch, and conditional nodes—shows EL file syntax, data context handling, parameter settings, and provides a concrete e‑commerce workflow example, concluding with performance and summary remarks.

Top Architect
Top Architect
Top Architect
Liteflow Rule Engine: Concepts, Usage, and Business Practice

1 前言

In daily development, serial or parallel business processes often lack correlation; using strategy and template patterns can solve this, but code can become scattered. Introducing a rule engine from a global perspective addresses this problem – the liteflow engine.

2 liteflow 规则引擎

liteflow is a lightweight yet powerful rule engine that works out‑of‑the‑box and can quickly handle complex rule orchestration. It supports multiple rule file formats (xml/json/yaml) and storage options (SQL, ZK, Nacos, Apollo).

liteflow can support complex flows, as shown in the diagram below.

Hot‑deployment is also supported; modifying rule files takes effect in real time.

3 liteflow 的使用方法

3.1 组件

The components correspond to nodes in rule files. Types include:

普通组件 – implement NodeComponent , used in when and then logic. Override iaAccess , isContinueOnError , and isEnd as needed.

选择组件 – similar to a Java switch , extend NodeSwitchComponent and implement processSwitch .

条件组件 – if component, extend NodeIfComponent and override processIf .

# flow 规则表达式 选择组件
SWITCH(a).to(b, c);
# processSwitch 表达式需要返回的是 b 或者 c 字符串来执行相应的业务逻辑
# flow 规则表达式 条件组件
IF(x, a, b);

3.2 EL 规则文件

Rule files are usually written in XML. Examples of composition syntax:

# 文件编排, then 代表串行执行  when 表示并行执行
# 串行编排示例
THEN(a, b, c, d);
# 并行编排示例
WHEN(a, b, c);
# 串行和并行嵌套结合
THEN( a, WHEN(b, c, d), e);
# 选择编排示例
SWITCH(a).to(b, c, d);
# 条件编排示例
THEN(IF(x, a), b );

3.3 数据上下文

The data context is crucial for passing parameters between nodes. It can be set as a class type when executing a chain.

# 执行流程时,需要传递el文件,初始化参数以及上下文对象,这里的上下文可以设置多个
LiteflowResponse response = flowExecutor.execute2Resp("chain1", 流程初始参数, CustomContext.class);

3.4 参数配置

Configuration items include rule file location, retry count, thread‑pool settings for parallel nodes, and request‑id generator.

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: true

4 业务实践

A typical e‑commerce scenario: after an order is completed, grant points, send messages, and concurrently send SMS and email.

<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <chain name="test_flow">
        THEN(
            prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
        );
    </chain>
</flow>

The flow shows pre‑processing, context conversion, and node execution for each business step.

5 总结

Most of Liteflow’s work is done at startup—rule parsing, component registration, and assembly—resulting in high execution performance with detailed timing and statistics. This article covered Liteflow’s core concepts and practical usage.

Javarule engineworkflowSpring BootLiteFlow
Top Architect
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.