LiteFlow: A Java Flow Orchestration Framework Overview
LiteFlow is a lightweight Java flow‑orchestration framework that lets developers break complex business processes into independent Spring‑Boot node components, configure them via XML, and execute them with FlowExecutor, supporting conditional switches and loops while focusing on simple workflow modeling rather than role‑task management.
LiteFlow is a lightweight Java flow‑orchestration framework that helps developers simplify complex business logic by breaking it into independent, manageable nodes.
It is ideal for scenarios with intricate processes such as pricing engines or order handling, where each step can be represented as a separate component. It does not handle role‑task workflows; for those, tools like Flowable are recommended.
Basic usage : add the Maven dependency, create Spring Boot node components, and define the processing logic.
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>liteflow-spring-boot-starter</artifactId>
<version>2.12.3</version>
</dependency>Define node classes extending NodeComponent and override process() :
@Component
public class UserNode extends NodeComponent {
@Override
public void process() {
System.out.println("用户身份验证");
}
}
@Component
public class StorageNode extends NodeComponent {
@Override
public void process() {
System.out.println("库存检查");
}
}
@Component
public class MerchandiseNode extends NodeComponent {
@Override
public void process() {
System.out.println("价格确认");
}
}
@Component
public class OrderNode extends NodeComponent {
@Override
public void process() {
System.out.println("订单确认");
}
}Configure the flow in liteflow.xml :
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="orderProcessChain">
THEN(userNode, storageNode, merchandiseNode, orderNode);
</chain>
</flow>Load the XML via liteflow.rule-source=classpath:liteflow.xml in application.properties and invoke the chain in a controller:
@RestController
public class HelloController {
@Autowired
FlowExecutor flowExecutor;
@GetMapping("/hello")
public void hello() {
flowExecutor.execute2Resp("orderProcessChain");
}
}Conditional switch : implement a component extending NodeSwitchComponent that returns the next node name.
@LiteflowComponent("a")
public class ACmp extends NodeSwitchComponent {
@Override
public String processSwitch() throws Exception {
System.out.println("Acomp executed!");
return "c"; // jump to node c
}
}Define the switch in XML:
<chain name="chain1">
SWITCH(a).to(b, c);
</chain>Loop component : extend NodeForComponent and return an integer indicating the iteration count.
@LiteflowComponent("f")
public class FCmp extends NodeForComponent {
@Override
public int processFor() throws Exception {
// return loop count based on business logic
}
}Use it in XML:
<chain name="chain1">
FOR(f).DO(THEN(a, b));
</chain>LiteFlow thus provides a modular, extensible way to model and execute business workflows within Java backend applications.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
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.