JDEasyFlow is a general flow orchestration component, suitable for service orchestration, workflow, auditing, etc. The characteristics are easy use, flexible, easy extended. Developer can understand using it in 30 minutes, understand its principle half of the day.
JDEasyFlow bottom layer is flow engine/state machine.(select one when use it, flow engine is recommanded), this module supply flow orchestration ability base on JSON format flow definition.
BPMN module supply define flow based on BPMN and visualization ability. visualization is based on bpmn-js. The essence of this module is convert BPMN format definition to JDEasyFlow JSON format definition.
There are test cases in the test package of source code. You can run or debug directly to understand its usage and implement principle.
- Import easyflow-flow jar. take maven as example:
<dependency>
<groupId>com.jd.easyflow</groupId>
<artifactId>easyflow-flow</artifactId>
<version>{latestVersion}</version>
</dependency>
- Write flow definition. For example, the sequence is node001->node002->node003:
{"id": "quickstart_001", "name": "Quick Start 001",
"nodes": [
{"id": "node001","name": "Node001","action": {"createExp": "new com.jd.easyflow.flow.quickstart.QuickStart001Node01Action()"},"start": true,"post": {"to": "node002"}},
{"id": "node002","name": "Node002","action": {"createExp": "new com.jd.easyflow.flow.quickstart.QuickStart002Node01Action()"},"post": {"to": "node003"}},
{"id": "node003","name": "Node003","action": {"createExp": "new com.jd.easyflow.flow.quickstart.QuickStart003Node01Action()"}}
]
}
QuickStart001Node01Action and so on is java node action class.
- Write the code of loading flow engine when application start.
FlowEngineImpl flowEngine = new FlowEngineImpl();
flowEngine.setFlowPath("classpath:flow/quickstart/quickstart_001.json");
flowEngine.init();
You can define FlowEngineImpl bean in Spring.
- Write the code of invoking flow engine.
FlowParam param = new FlowParam("quickstart_001");
FlowResult result = flowEngine.execute(param);
The executing log are as follows:
[main ] INFO FlowEngineImpl - Start parsing definition files:easyflow-flow/target/test-classes/flow/quickstart/quickstart_001.json
[main ] INFO FlowEngineImpl - SART EXECUTE FLOW, flowId:quickstart_001 nodeIds:null
[main ] INFO BaseFlowRunner - EXECUTE NODE:node001
[main ] INFO QuickStart001Node01Action - Execute Node 001
[main ] INFO BaseFlowRunner - NEXT NODES:node002
[main ] INFO BaseFlowRunner - EXECUTE NODE:node002
[main ] INFO QuickStart002Node01Action - Execute Node 002
[main ] INFO BaseFlowRunner - NEXT NODES:node003
[main ] INFO BaseFlowRunner - EXECUTE NODE:node003
[main ] INFO QuickStart003Node01Action - Execute Node 003
[main ] INFO BaseFlowRunner - NEXT NODES:
[main ] INFO QuickStartTest - Execute finish, current node is:node003
Above is simple usecase, JDEasyFlow support many configurations and use cases. More can be seen in wiki doc.
Open flow designer with path easyflow-flow-bpmn/BPMNDesigner.html. Click import button, import easyflow-flow-bpmn/src/test/resources/flow/quickstart/quickstart_001.bpmn file. You can see bpmn flow definition of equal JSON format. You only need set flowPaser of FlowEngineImpl to BpmnFlowParser when use.
Process module provide persistence and task audit ability based on flow engine, needing relation database support. Sample application in the source code can be started as follows:
- Checkout source code.
- Install relation database system, for example MYSQL(You should obey their license).
- Create database and table. Database name is easyflow, Table schema can be referred by create_all_table.sql and sample_form_template.sql.
- Config database connection info in application-open-all.yml of sample module, Import database driver jar in pom.xml of sample module.
- Build the project. Start IntegrationOpenApplication. Access http://localhost:9888.
JDEasyFlow has very flexible extension ability. You can implement more features based on current component. For example flow data persistence, auditting, exception retry.
mailTo: liyuliang5@jd.com