Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added jbpm-vertx #428

Open
wants to merge 7 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,8 @@ with link:https://micrometer.io/[Micrometer] and send them to backends such as P

The link:web-graphql-examples/README.adoc[Vert.x Web GraphQL] examples contain simple client/server GraphQL applications built with https://vertx.io/docs/vertx-web-graphql/java/[Vert.x Web GraphQL] and the https://www.graphql-java.com/[GraphQL-Java] library.

=== Jbpm examples

The link:jbpm-examples/README.adoc[Vert.x Jbpm] examples contain sample code for integrating Jbpm with vertx.


36 changes: 36 additions & 0 deletions jbpm-examples/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
= Vert.x Jbpm examples

This project will demonstrate the usage of jbpm to create business processes(using jbpm) inside vertx. This example makes use of vertx event bus. A sender verticle will send a message, which will be received by a jbpm verticle. This verticle will start a jbpm process and pass this message as a parameter to the process. Process will print this message in one of it's steps(script task).

The link:src/main/java/io/vertx/example/jbpm/JbpmVerticle.java[JbpmVerticle.java] shows the Verticle with embedded Jbpm.

The link:src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java[MsgSenderVerticle.java] shows the Verticle which will publish a message to event bus..

*Additional Info*

jbpm-examples project will be packaged as a kjar to include jbpm artifacts(bpmn and kie-module).

*Run verticles*

Create a uber jar with all dependencies. pom file has a maven-shade-plugin for this.
To create a uber jar, run maven command -

[source,java]
----
mvn package
----

Once the jar is created, run the following vertx commands for deploying verticles.

Run the message sender verticle
[source,java]
----
vertx run io.vertx.example.jbpm.MsgSenderVerticle -cp <uber-jar-name.jar> -cluster
----

Run the jbpm verticle
[source,java]
----
vertx run io.vertx.example.jbpm.JbpmVerticle -cp <uber-jar-name.jar> -cluster
----

178 changes: 178 additions & 0 deletions jbpm-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>vertx-examples</artifactId>
<groupId>io.vertx</groupId>
<version>4.1.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>kjar</packaging>

<artifactId>jbpm-examples</artifactId>

<properties>
<jbpm.version>7.40.0.Final</jbpm.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<assertj-core.version>3.8.0</assertj-core.version>
</properties>

<dependencies>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${jbpm.version}</version>
</dependency>

<!-- jBPM engine core dependencies -->
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-flow-builder</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-bpmn2</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-runtime-manager</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-persistence-jpa</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-query-jpa</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-audit</artifactId>
<version>${jbpm.version}</version>
</dependency>

<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-kie-services</artifactId>
<version>${jbpm.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>7.7.0.Final</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/kie.conf</resource>
</transformer>
</transformers>
<artifactSet>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<versionRange>[7.0.0,)</versionRange>
<goals>
<goal>build</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.vertx.example.jbpm;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

import org.jbpm.workflow.instance.WorkflowProcessInstance;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;


public class JbpmVerticle extends AbstractVerticle {

@Override
public void start() {
System.out.println("Starting JbpmVerticle");

EventBus eb = vertx.eventBus();

/* Initializing kie-session to start a process */
KieContainer container = KieServices.Factory.get().getKieClasspathContainer();
KieSession ksession = container.newKieSession("sampleSession");

eb.consumer("process-message", message -> {
System.out.println("Received message on consumer " + message.body());
Map<String, Object> input = new HashMap<String, Object>();
input.put("message", message.body());

// Start a process
WorkflowProcessInstance p = (WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.hello", input);
System.out.println("Generated Process ID: " + p.getId());
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.vertx.example.jbpm;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.EventBus;


public class MsgSenderVerticle extends AbstractVerticle {

@Override
public void start() {
System.out.println("Starting MsgSenderVerticle");
EventBus eb = vertx.eventBus();
vertx.setPeriodic(10000, v -> eb.publish("process-message", "start process!"));
}

}
5 changes: 5 additions & 0 deletions jbpm-examples/src/main/resources/META-INF/kmodule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="kbase" packages="io.vertx.example.jbpm" default="true">
<ksession name="sampleSession" type="stateful" default="true"/>
</kbase>
</kmodule>
65 changes: 65 additions & 0 deletions jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- origin at X=0.0 Y=0.0 -->
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:java="http://www.java.com/javaTypes" xmlns:tns="http://www.jboss.org/drools" xmlns="http://www.jboss.org/drools" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd http://www.jboss.org/drools drools.xsd http://www.bpsim.org/schemas/1.0 bpsim.xsd" id="Definition" exporter="org.eclipse.bpmn2.modeler.core" exporterVersion="1.5.0.Final-v20180515-1642-B1" expressionLanguage="http://www.mvel.org/2.0" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes">
<bpmn2:itemDefinition id="ItemDefinition_89" isCollection="false" structureRef="java.lang.String"/>
<bpmn2:process id="com.sample.bpmn.hello" name="Hello World" isExecutable="true" processType="Private">
<bpmn2:property id="message" itemSubjectRef="ItemDefinition_89" name="message"/>
<bpmn2:scriptTask id="_2" name="Hello">
<bpmn2:extensionElements>
<tns:metaData name="elementname">
<tns:metaValue><![CDATA[Hello]]></tns:metaValue>
</tns:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_1-_2</bpmn2:incoming>
<bpmn2:outgoing>_2-_3</bpmn2:outgoing>
<bpmn2:script>System.out.println(&quot;Message received inside process -- &quot;+message);</bpmn2:script>
</bpmn2:scriptTask>
<bpmn2:startEvent id="_1">
<bpmn2:extensionElements>
<tns:metaData name="elementname">
<tns:metaValue><![CDATA[]]></tns:metaValue>
</tns:metaData>
</bpmn2:extensionElements>
<bpmn2:outgoing>_1-_2</bpmn2:outgoing>
</bpmn2:startEvent>
<bpmn2:endEvent id="_3">
<bpmn2:extensionElements>
<tns:metaData name="elementname">
<tns:metaValue><![CDATA[]]></tns:metaValue>
</tns:metaData>
</bpmn2:extensionElements>
<bpmn2:incoming>_2-_3</bpmn2:incoming>
<bpmn2:terminateEventDefinition id="TerminateEventDefinition_1"/>
</bpmn2:endEvent>
<bpmn2:sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2"/>
<bpmn2:sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3"/>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_Process_1" bpmnElement="com.sample.bpmn.hello">
<bpmndi:BPMNShape id="BPMNShape_ScriptTask_1" bpmnElement="_2">
<dc:Bounds height="48.0" width="80.0" x="96.0" y="16.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="17.0" width="32.0" x="120.0" y="31.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_StartEvent_1" bpmnElement="_1">
<dc:Bounds height="36.0" width="36.0" x="30.0" y="22.0"/>
<bpmndi:BPMNLabel/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_EndEvent_1" bpmnElement="_3">
<dc:Bounds height="36.0" width="36.0" x="210.0" y="22.0"/>
<bpmndi:BPMNLabel/>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_1" bpmnElement="_1-_2" sourceElement="BPMNShape_StartEvent_1" targetElement="BPMNShape_ScriptTask_1">
<di:waypoint xsi:type="dc:Point" x="66.0" y="40.0"/>
<di:waypoint xsi:type="dc:Point" x="96.0" y="40.0"/>
<bpmndi:BPMNLabel/>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="BPMNEdge_SequenceFlow_2" bpmnElement="_2-_3" sourceElement="BPMNShape_ScriptTask_1" targetElement="BPMNShape_EndEvent_1">
<di:waypoint xsi:type="dc:Point" x="176.0" y="40.0"/>
<di:waypoint xsi:type="dc:Point" x="210.0" y="40.0"/>
<bpmndi:BPMNLabel/>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.vertx.example.jbpm;

import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.file.FileSystemOptions;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(VertxExtension.class)
public class JbpmVerticleTest {

Vertx vertx;

@BeforeEach
void prepare() {
vertx = Vertx.vertx(new VertxOptions()
.setMaxEventLoopExecuteTime(1000)
.setPreferNativeTransport(true)
.setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(true)));
}

@Test
@DisplayName("Deploy JbpmVerticles")
void deployJbpmVerticle(VertxTestContext testContext) {
vertx.deployVerticle(new JbpmVerticle(), testContext.succeeding(id -> testContext.completeNow()));
vertx.deployVerticle(new MsgSenderVerticle(), testContext.succeeding(id -> testContext.completeNow()));
}

}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<module>web-api-service-example</module>
<module>cassandra-examples</module>
<module>web-graphql-examples</module>
<module>jbpm-examples</module>
</modules>

<profiles>
Expand Down