How Compileflow Accelerates Java Workflow Development with High Performance
This article introduces Compileflow, a lightweight and high‑performance Java workflow engine, outlines its key features, shows how to integrate it with Maven, demonstrates code generation and unit testing, and highlights practical tips and limitations.
What Is Compileflow
Compileflow is a lightweight, high‑performance, integrable, and extensible workflow engine.
The Compileflow Process engine is one of Alibaba's TBBPM workflow engines, focusing on pure in‑memory, stateless execution by converting workflow files into compiled Java code, offering simplicity and efficiency. It powers many core systems in Alibaba's middle‑platform, such as trading.
Compileflow enables developers to design business processes with a visual editor, bridging the gap between business designers and engineers.
Feature List
High performance: converts workflow files into compiled Java code for fast execution.
Rich application scenarios: widely used in Alibaba's middle‑platform, supporting shopping, trading, fulfillment, finance, and more.
Easy integration: lightweight design allows seamless integration into various solutions.
Comprehensive plugin support: IntelliJ IDEA and Eclipse plugins provide real‑time Java code generation and preview.
Exportable workflow diagrams as SVG and unit‑test code.
Supports code triggers based on Java reflection and Spring container.
Quick Start
Add the Compileflow JAR dependency:
<code><dependency>
<groupId>com.alibaba.compileflow</groupId>
<artifactId>compileflow</artifactId>
<version>1.0.0</version>
</dependency>
</code>Create a simple workflow diagram with Compileflow.
IDEA plugin allows you to view the generated Java code for the workflow:
<code>public class PigFlow implements ProcessInstance {
private Integer price = null;
public Map<String, Object> execute(Map<String, Object> _pContext) throws Exception {
price = (Integer) DataType.transfer(_pContext.get("price"), Integer.class);
Map<String, Object> _pResult = new HashMap<>();
decision8();
// AutoTaskNode: payment
((BizMock) ObjectFactory.getInstance("com.example.compileflow.bean.BizMock")).payMoney(price);
_pResult.put("price", price);
return _pResult;
}
private void decision8() {
// DecisionNode: calculate fee
bizMockCalMoney();
if (price >= 100) {
// price >= 100
{
// ScriptTaskNode: discount for high price
IExpressContext<String, Object> nfScriptContext = new DefaultContext<>();
nfScriptContext.put("price", price);
price = (Integer) ScriptExecutorProvider.getInstance()
.getScriptExecutor("QL").execute("price*2", nfScriptContext);
}
} else {
// price < 100
{
// ScriptTaskNode: discount for low price
IExpressContext<String, Object> nfScriptContext = new DefaultContext<>();
nfScriptContext.put("price", price);
price = (Integer) ScriptExecutorProvider.getInstance()
.getScriptExecutor("QL").execute("(round(price*0.5,0)).intValue()", nfScriptContext);
}
}
}
private void bizMockCalMoney() {
price = ((BizMock) ObjectFactory.getInstance("com.example.compileflow.bean.BizMock")).calMoney(price);
}
}
</code>Right‑click the BPM file to generate a unit test.
<code>@Test
public void testProcess() throws Exception {
String code = "pig";
ProcessEngine<TbbpmModel> engine = ProcessEngineFactory.getProcessEngine();
System.out.println(engine.getJavaCode(code));
Map<String, Object> context = new HashMap<>();
context.put("price", 10);
Map<String, Object> execute = engine.execute(code, context);
System.out.println(execute);
}
</code>Run the unit test to see the process output.
<code>假装在计算金额~~~~~~10
支付了~~~~~~5
</code>Summary
Compileflow is extremely easy to get started with, lowering the learning curve of workflow development.
The Compileflow IDEA designer plugin (compatible with version 2021) has some compatibility issues.
The automatically generated unit‑test code depends on an older JUnit version and does not support JUnit 5.
References
Compileflow IDEA designer plugin: https://github.com/compileflow/compileflow-designer-upgrade
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
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.