diff --git a/README.adoc b/README.adoc index df45eaa9a..3b0311e17 100644 --- a/README.adoc +++ b/README.adoc @@ -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. diff --git a/jbpm-examples/README.adoc b/jbpm-examples/README.adoc new file mode 100644 index 000000000..2c209a040 --- /dev/null +++ b/jbpm-examples/README.adoc @@ -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 -cluster +---- + +Run the jbpm verticle +[source,java] +---- +vertx run io.vertx.example.jbpm.JbpmVerticle -cp -cluster +---- + diff --git a/jbpm-examples/pom.xml b/jbpm-examples/pom.xml new file mode 100644 index 000000000..396b225fb --- /dev/null +++ b/jbpm-examples/pom.xml @@ -0,0 +1,178 @@ + + + + vertx-examples + io.vertx + 4.1.2 + + 4.0.0 + kjar + + jbpm-examples + + + 7.40.0.Final + 11 + 11 + 5.6.2 + 3.8.0 + + + + + + io.vertx + vertx-core + ${project.version} + + + + ch.qos.logback + logback-classic + 1.2.3 + + + + org.kie + kie-api + ${jbpm.version} + + + + + org.jbpm + jbpm-flow + ${jbpm.version} + + + + org.jbpm + jbpm-flow-builder + ${jbpm.version} + + + + org.jbpm + jbpm-bpmn2 + ${jbpm.version} + + + + org.jbpm + jbpm-runtime-manager + ${jbpm.version} + + + + org.jbpm + jbpm-persistence-jpa + ${jbpm.version} + + + + org.jbpm + jbpm-query-jpa + ${jbpm.version} + + + + org.jbpm + jbpm-audit + ${jbpm.version} + + + + org.jbpm + jbpm-kie-services + ${jbpm.version} + + + + + io.vertx + vertx-junit5 + ${project.version} + test + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + + + + + + org.kie + kie-maven-plugin + 7.7.0.Final + true + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + + + + META-INF/kie.conf + + + + + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.kie + kie-maven-plugin + [7.0.0,) + + build + + + + + + + + + + + + + + + + diff --git a/jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java b/jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java new file mode 100644 index 000000000..54805ee3e --- /dev/null +++ b/jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java @@ -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 input = new HashMap(); + 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()); + }); + } + +} diff --git a/jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java b/jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java new file mode 100644 index 000000000..8151a8ad6 --- /dev/null +++ b/jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java @@ -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!")); + } + +} diff --git a/jbpm-examples/src/main/resources/META-INF/kmodule.xml b/jbpm-examples/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 000000000..4bb27c0db --- /dev/null +++ b/jbpm-examples/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn b/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn new file mode 100644 index 000000000..0f219cb46 --- /dev/null +++ b/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn @@ -0,0 +1,65 @@ + + + + + + + + + + + + + _1-_2 + _2-_3 + System.out.println("Message received inside process -- "+message); + + + + + + + + _1-_2 + + + + + + + + _2-_3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java b/jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java new file mode 100644 index 000000000..962d961d0 --- /dev/null +++ b/jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java @@ -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())); + } + +} diff --git a/pom.xml b/pom.xml index 51c08423b..2cf73afce 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,7 @@ web-api-service-example cassandra-examples web-graphql-examples + jbpm-examples