All examples used in this article are available in the Flowable examples Github repository. The flowable-intro Maven project can be imported into your favourite IDE and you can play with the examples from there.
Now let's get started with a simple BPMN example project by creating a new Maven project and add the Flowable Engine as a dependency, like you can see in the following snippet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<name>Flowable Intro</name> | |
<groupId>org.flowable.examples</groupId> | |
<artifactId>flowable-intro</artifactId> | |
<packaging>jar</packaging> | |
<version>1.0</version> | |
<dependencies> | |
<!-- Flowable dependencies --> | |
<dependency> | |
<groupId>org.flowable</groupId> | |
<artifactId>flowable-engine</artifactId> | |
<version>6.0.0.RC1</version> | |
</dependency> | |
<dependency> | |
<groupId>com.h2database</groupId> | |
<artifactId>h2</artifactId> | |
<version>1.3.176</version> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-api</artifactId> | |
<version>1.7.6</version> | |
</dependency> | |
<dependency> | |
<groupId>org.slf4j</groupId> | |
<artifactId>slf4j-log4j12</artifactId> | |
<version>1.7.6</version> | |
</dependency> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.11</version> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | |
<bean id="processEngineConfiguration" | |
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration"> | |
<property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000;MVCC=TRUE" /> | |
<property name="jdbcDriver" value="org.h2.Driver" /> | |
<property name="jdbcUsername" value="sa" /> | |
<property name="jdbcPassword" value="" /> | |
<property name="databaseSchemaUpdate" value="true" /> | |
</bean> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<definitions id="introExample" | |
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | |
xmlns:flowable="http://flowable.org/bpmn" | |
targetNamespace="http://flowable.org/examples"> | |
<process id="intro"> | |
<startEvent id="start"/> | |
<sequenceFlow id="flow1" sourceRef="start" targetRef="introTask" /> | |
<serviceTask id="introTask" flowable:class="org.flowable.intro.IntroTask" /> | |
<sequenceFlow id="flow2" sourceRef="introTask" targetRef="end" /> | |
<endEvent id="end" /> | |
</process> | |
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IntroTask implements JavaDelegate { | |
public void execute(DelegateExecution execution) { | |
if (execution.hasVariable("intro")) { | |
System.out.println("Intro variable available with value " + execution.getVariable("intro")); | |
execution.setVariable("variablePresent", true); | |
} else { | |
System.out.println("Intro variable not available"); | |
execution.setVariable("variablePresent", false); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testIntroProcess() { | |
// Create Flowable engine | |
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); | |
// Get main service interfaces | |
RepositoryService repositoryService = processEngine.getRepositoryService(); | |
RuntimeService runtimeService = processEngine.getRuntimeService(); | |
HistoryService historyService = processEngine.getHistoryService(); | |
// Deploy intro process definition | |
repositoryService.createDeployment().name("intro") | |
.addClasspathResource("intro.bpmn20.xml") | |
.deploy(); | |
// Start intro process instance | |
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("intro"); | |
assertTrue(processInstance.isEnded()); | |
.... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public testIntroProcess() { | |
.... | |
HistoricVariableInstance historicVariable = historyService.createHistoricVariableInstanceQuery() | |
.processInstanceId(processInstance.getId()) | |
.singleResult(); | |
assertEquals("variablePresent", historicVariable.getVariableName()); | |
assertEquals(false, historicVariable.getValue()); | |
processInstance = runtimeService.startProcessInstanceByKey("intro", Collections.singletonMap("intro", (Object) "a test intro value")); | |
List<HistoricVariableInstance> historicVariables = historyService | |
.createHistoricVariableInstanceQuery() | |
.processInstanceId(processInstance.getId()) | |
.orderByVariableName() | |
.asc() | |
.list(); | |
assertEquals("intro", historicVariables.get(0).getVariableName()); | |
assertEquals("a test intro value", historicVariables.get(0).getValue()); | |
assertEquals("variablePresent", historicVariables.get(1).getVariableName()); | |
assertEquals(true, historicVariables.get(1).getValue()); | |
processEngine.close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.flowable</groupId> | |
<artifactId>flowable-dmn-engine</artifactId> | |
<version>6.0.0.RC1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.flowable</groupId> | |
<artifactId>flowable-dmn-engine-configurator</artifactId> | |
<version>6.0.0.RC1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | |
<bean id="processEngineConfiguration" | |
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration"> | |
<property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000;MVCC=TRUE" /> | |
<property name="jdbcDriver" value="org.h2.Driver" /> | |
<property name="jdbcUsername" value="sa" /> | |
<property name="jdbcPassword" value="" /> | |
<property name="databaseSchemaUpdate" value="true" /> | |
<property name="configurators"> | |
<list> | |
<ref bean="dmnEngineConfigurator"/> | |
</list> | |
</property> | |
</bean> | |
<bean id="dmnEngineConfigurator" class="org.flowable.dmn.engine.configurator.DmnEngineConfigurator" /> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<definitions id="dmnExample" | |
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | |
xmlns:flowable="http://flowable.org/bpmn" | |
targetNamespace="http://flowable.org/examples"> | |
<process id="dmn"> | |
<startEvent id="start"/> | |
<sequenceFlow id="flow1" sourceRef="start" targetRef="dmnTask" /> | |
<serviceTask id="dmnTask" flowable:type="dmn"> | |
<extensionElements> | |
<flowable:field name="decisionTableReferenceKey"> | |
<flowable:string><![CDATA[intro]]></flowable:string> | |
</flowable:field> | |
</extensionElements> | |
</serviceTask> | |
<sequenceFlow id="flow2" sourceRef="dmnTask" targetRef="end" /> | |
<endEvent id="end" /> | |
</process> | |
</definitions> |
With all definitions in place we can now test this setup and run the BPMN Engine together with the DMN Engine. The main difference is that we need to deploy both the BPMN XML file as well as the DMN XML file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deploy intro process definition | |
repositoryService.createDeployment().name("dmn") | |
.addClasspathResource("dmn.bpmn20.xml") | |
.addClasspathResource("intro.dmn") | |
.deploy(); |
To complete the introduction, let's also have a quick look on how to enable the Flowable 5 embedded engine. The Flowable 5 embedded engine is a handy way to migrate from the Flowable 5 Engine to the Flowable 6 Engine. All running process instances will be executed with the same logic as the Flowable 5 Engine, and existing process definitions will be labeled with the version 5 tag. New process definitions will be deployed as Flowable 6 process definitions by default, but this can be overridden using a deployment property. A possible migration strategy is to let the running process instances end on the Flowable 5 logic, and let all new process instances run with the new Flowable 6 logic.
To run the embedded Flowable 5 engine we need to add the compatibility dependency, that is again an optional component for the Flowable 6 engine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.flowable</groupId> | |
<artifactId>flowable5-compatibility</artifactId> | |
<version>6.0.0.RC1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | |
<bean id="processEngineConfiguration" | |
class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration"> | |
<property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000;MVCC=TRUE" /> | |
<property name="jdbcDriver" value="org.h2.Driver" /> | |
<property name="jdbcUsername" value="sa" /> | |
<property name="jdbcPassword" value="" /> | |
<property name="databaseSchemaUpdate" value="true" /> | |
<property name="flowable5CompatibilityEnabled" value="true" /> | |
</bean> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deploy intro process definition | |
Deployment deployment = repositoryService.createDeployment().name("intro") | |
.addClasspathResource("intro.bpmn20.xml") | |
.deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, true) | |
.deploy(); | |
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() | |
.deploymentId(deployment.getId()) | |
.singleResult(); | |
assertEquals("intro", processDefinition.getKey()); | |
assertEquals("v5", processDefinition.getEngineVersion()); |
With this article we tried to show that with Flowable 6, the same lightweight and modular approach has been taken as with Flowable 5 and that it's really easy to plugin the DMN engine and enable the Flowable 5 embedded engine. Also, the APIs are still the same so it should be easy to get started with the Flowable 6 Engine. Feedback is always welcome on this article and you can always ask questions and provide feedback on the Flowable forum.