Backend Development 10 min read

Mastering LiteFlow: A Lightweight Rule Engine for Spring Boot Workflows

This article introduces LiteFlow, a lightweight yet powerful rule engine for Spring Boot, explains its architecture, supported rule formats, core components, EL rule files, data context handling, configuration options, and demonstrates a real‑world e‑commerce order processing workflow with code examples.

macrozheng
macrozheng
macrozheng
Mastering LiteFlow: A Lightweight Rule Engine for Spring Boot Workflows

1 Introduction

In everyday development, serial or parallel business processes often lack correlation, making strategy and template patterns useful but cumbersome due to many files. Introducing a rule engine from a global perspective solves this, and the featured engine is

liteflow

.

2 LiteFlow Rule Engine

liteflow

is a lightweight and powerful rule engine that works out‑of‑the‑box, allowing complex rule orchestration quickly. It supports multiple rule file formats such as XML, JSON, and YAML, and can store rules in SQL, Zookeeper, Nacos, Apollo, etc.

The overall architecture is shown below:

Usage starts by obtaining a data context, parsing the corresponding rule file, and executing the chain via the LiteFlow executor. Each chain contains independent business nodes that can run scripts in Groovy, JavaScript, Python, Lua, etc.

<code># liteflow rule engine official site
https://liteflow.yomahub.com
# Spring Boot integration
<dependency>
    <groupId>com.yomahub</groupId>
    <artifactId>liteflow-spring-boot-starter</artifactId>
    <version>2.10.6</version>
</dependency>
</code>
liteflow

can handle complex flows such as the diagram below:

It also supports hot deployment, allowing real‑time replacement or addition of nodes by updating rule files.

3 How to Use LiteFlow

3.1 Components

Components correspond to nodes in rule files. Common component types include:

Ordinary Component – implements

NodeComponent

, used in

when

and

then

logic. Override

process

, optionally

iaAccess

,

isContinueOnError

, and

isEnd

.

Switch Component – extends

NodeSwitchComponent

and implements

processSwitch

to choose the next node, similar to a Java

switch

.

Condition Component – extends

NodeIfComponent

and overrides

processIf

to return true/false.

3.2 EL Rule Files

Rule files are written in XML using EL expressions. Example snippets:

<code># Serial execution example
THEN(a, b, c, d);
# Parallel execution example
WHEN(a, b, c);
# Nested serial and parallel
THEN(a, WHEN(b, c, d), e);
# Switch example
SWITCH(a).to(b, c, d);
# Condition example
THEN(IF(x, a), b);
</code>

3.3 Data Context

The data context carries parameters between nodes. Execution typically looks like:

<code>LiteflowResponse response = flowExecutor.execute2Resp("chain1", initialParams, CustomContext.class);
</code>

The first node usually injects input parameters into the context for downstream nodes.

3.4 Parameter Configuration

Configuration items include rule file locations, retry counts, thread pool settings for parallel nodes, request‑ID generator, and context slot size. Example YAML fragment:

<code>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
</code>

4 Business Practice

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

<code>&lt;flow&gt;
    &lt;chain name="test_flow"&gt;
        THEN(
            prepareTrade, grantScore, sendMq, WHEN(sendEmail, sendPhone)
        );
    &lt;/chain&gt;
&lt;/flow&gt;
</code>

The flow executes asynchronously, passing parameters and invoking the defined chain.

Before processing, input data is transformed into a context object for easy parameter passing.

During the points‑granting node, the context is accessed to perform business logic, and

isAccess

can be overridden to decide whether to execute the node.

5 Summary

Most of LiteFlow’s work—rule parsing, component registration, and assembly—occurs at startup, delivering high execution performance. It can log each business step’s duration and statistics. This article covered LiteFlow’s core concepts, usage methods, and provided a complete example; the source code is available on GitHub.

Javarule engineworkflowSpring BootLiteFlow
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

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.