From 40f59b8af8aa6269949973332094da5f6ebcfe98 Mon Sep 17 00:00:00 2001 From: Prasanth Nair Date: Fri, 30 Jul 2021 12:33:29 -0700 Subject: [PATCH 1/6] added jbpm-vertx --- README.adoc | 3 + jbpm-examples/README.adoc | 11 ++ jbpm-examples/pom.xml | 113 ++++++++++++++++++ .../io/vertx/example/jbpm/JbpmVerticle.java | 27 +++++ .../src/main/resources/META-INF/kmodule.xml | 5 + .../io.vertx.example.jbpm/sample.bpmn | 53 ++++++++ .../vertx/example/jbpm/JbpmVerticleTest.java | 32 +++++ pom.xml | 1 + 8 files changed, 245 insertions(+) create mode 100644 jbpm-examples/README.adoc create mode 100644 jbpm-examples/pom.xml create mode 100644 jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java create mode 100644 jbpm-examples/src/main/resources/META-INF/kmodule.xml create mode 100644 jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn create mode 100644 jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java 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..1d63c11d0 --- /dev/null +++ b/jbpm-examples/README.adoc @@ -0,0 +1,11 @@ += Vert.x Jbpm examples + +This project will demonstrate the usage of jbpm to create business processes inside vertx. + +The link:src/main/java/io/vertx/example/jbpm/JbpmVerticle.java[JbpmVerticle.java] shows the Verticle with embedded Jbpm. + +Process Definition can be found in :src/main/resources/io/vertx/example/jbpm/sample.bpmn[sample.bpmn] + +The link:src/main/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the +junit test for running the verticle. + diff --git a/jbpm-examples/pom.xml b/jbpm-examples/pom.xml new file mode 100644 index 000000000..3e17ef24f --- /dev/null +++ b/jbpm-examples/pom.xml @@ -0,0 +1,113 @@ + + + + vertx-examples + io.vertx + 4.1.2 + + 4.0.0 + + 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 + + + + + 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..71ba6e861 --- /dev/null +++ b/jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java @@ -0,0 +1,27 @@ +package io.vertx.example.jbpm; + +import io.vertx.core.AbstractVerticle; +import org.jbpm.workflow.instance.WorkflowProcessInstance; +import org.kie.api.KieServices; +import org.kie.api.runtime.KieContainer; +import org.kie.api.runtime.KieSession; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class JbpmVerticle extends AbstractVerticle { + + private static final Logger LOGGER = LoggerFactory.getLogger(JbpmVerticle.class); + + @Override + public void start() { + LOGGER.info("Starting JbpmVerticle"); + + /* Starting KieContainer and invoking a process */ + KieContainer container = KieServices.Factory.get().getKieClasspathContainer(); + KieSession ksession = container.newKieSession("sampleSession"); + WorkflowProcessInstance p = (WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.hello"); + LOGGER.info("Generated Process ID: " + p.getId()); + } + + +} 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..2c94382ab --- /dev/null +++ b/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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..169186fe1 --- /dev/null +++ b/jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java @@ -0,0 +1,32 @@ +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 JbpmVerticle") + void deployJbpmVerticle(VertxTestContext testContext) { + vertx.deployVerticle(new JbpmVerticle(), 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 From 4308c092a8ee29a44f78e852e2f9ba3efb973bce Mon Sep 17 00:00:00 2001 From: Prasanth Nair Date: Tue, 10 Aug 2021 01:03:14 -0700 Subject: [PATCH 2/6] added eventbus --- jbpm-examples/README.adoc | 11 +- jbpm-examples/pom.xml | 65 +++++++++++ .../io/vertx/example/jbpm/JbpmVerticle.java | 35 ++++-- .../vertx/example/jbpm/MsgSenderVerticle.java | 19 ++++ .../io.vertx.example.jbpm/sample.bpmn | 104 ++++++++++-------- .../vertx/example/jbpm/JbpmVerticleTest.java | 3 +- 6 files changed, 177 insertions(+), 60 deletions(-) create mode 100644 jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java diff --git a/jbpm-examples/README.adoc b/jbpm-examples/README.adoc index 1d63c11d0..1beb21f59 100644 --- a/jbpm-examples/README.adoc +++ b/jbpm-examples/README.adoc @@ -1,6 +1,6 @@ = Vert.x Jbpm examples -This project will demonstrate the usage of jbpm to create business processes inside vertx. +This project will demonstrate the usage of jbpm to create business processes 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. @@ -9,3 +9,12 @@ Process Definition can be found in :src/main/resources/io/vertx/example/jbpm/sa The link:src/main/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the junit test for running the verticle. +To run verticles + +Create a uber jar with all dependencies. pom has a maven-shade-plugin for this. +run in command line - mvn package. + +vertx run io.vertx.example.jbpm.MsgSenderVerticle -cp -cluster + +vertx run io.vertx.example.jbpm.JbpmVerticle -cp -cluster + diff --git a/jbpm-examples/pom.xml b/jbpm-examples/pom.xml index 3e17ef24f..396b225fb 100644 --- a/jbpm-examples/pom.xml +++ b/jbpm-examples/pom.xml @@ -8,6 +8,7 @@ 4.1.2 4.0.0 + kjar jbpm-examples @@ -109,5 +110,69 @@ + + + + + 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 index 71ba6e861..54805ee3e 100644 --- a/jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java +++ b/jbpm-examples/src/main/java/io/vertx/example/jbpm/JbpmVerticle.java @@ -1,27 +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; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + public class JbpmVerticle extends AbstractVerticle { - private static final Logger LOGGER = LoggerFactory.getLogger(JbpmVerticle.class); + @Override + public void start() { + System.out.println("Starting JbpmVerticle"); + + EventBus eb = vertx.eventBus(); - @Override - public void start() { - LOGGER.info("Starting JbpmVerticle"); + /* Initializing kie-session to start a process */ + KieContainer container = KieServices.Factory.get().getKieClasspathContainer(); + KieSession ksession = container.newKieSession("sampleSession"); - /* Starting KieContainer and invoking a process */ - KieContainer container = KieServices.Factory.get().getKieClasspathContainer(); - KieSession ksession = container.newKieSession("sampleSession"); - WorkflowProcessInstance p = (WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.hello"); - LOGGER.info("Generated Process ID: " + p.getId()); - } + 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..032c5f156 --- /dev/null +++ b/jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java @@ -0,0 +1,19 @@ +package io.vertx.example.jbpm; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.core.eventbus.EventBus; +import io.vertx.core.spi.cluster.ClusterManager; +import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; + +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/io.vertx.example.jbpm/sample.bpmn b/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn index 2c94382ab..0f219cb46 100644 --- a/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn +++ b/jbpm-examples/src/main/resources/io.vertx.example.jbpm/sample.bpmn @@ -1,53 +1,65 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + _1-_2 + _2-_3 + System.out.println("Message received inside process -- "+message); + + + + + + + + _1-_2 + + + + + + + + _2-_3 + + + + + + + + + + + + - - + + + - - + + + - - - + + + + - - - + + + + - - \ No newline at end of file + \ 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 index 169186fe1..962d961d0 100644 --- a/jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java +++ b/jbpm-examples/src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java @@ -24,9 +24,10 @@ void prepare() { } @Test - @DisplayName("Deploy JbpmVerticle") + @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())); } } From 19beb7f189049f052a139926dbde90ab523812c7 Mon Sep 17 00:00:00 2001 From: Prasanth Nair Date: Tue, 10 Aug 2021 11:25:18 -0700 Subject: [PATCH 3/6] fixes --- jbpm-examples/README.adoc | 8 +++++++- .../java/io/vertx/example/jbpm/MsgSenderVerticle.java | 5 +---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/jbpm-examples/README.adoc b/jbpm-examples/README.adoc index 1beb21f59..5f509ff16 100644 --- a/jbpm-examples/README.adoc +++ b/jbpm-examples/README.adoc @@ -1,6 +1,6 @@ = Vert.x Jbpm examples -This project will demonstrate the usage of jbpm to create business processes 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). +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. @@ -9,11 +9,17 @@ Process Definition can be found in :src/main/resources/io/vertx/example/jbpm/sa The link:src/main/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the junit test for running the verticle. +Additional Info + +jbpm-examples project will be packaged as a kjar to include jbpm artifacts(bpmn and kie-module). + To run verticles Create a uber jar with all dependencies. pom has a maven-shade-plugin for this. run in command line - mvn package. +Once the jar is created, run the vertx commands for deploying verticles. + vertx run io.vertx.example.jbpm.MsgSenderVerticle -cp -cluster vertx run io.vertx.example.jbpm.JbpmVerticle -cp -cluster 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 index 032c5f156..8151a8ad6 100644 --- a/jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java +++ b/jbpm-examples/src/main/java/io/vertx/example/jbpm/MsgSenderVerticle.java @@ -1,11 +1,8 @@ package io.vertx.example.jbpm; import io.vertx.core.AbstractVerticle; -import io.vertx.core.Vertx; -import io.vertx.core.VertxOptions; import io.vertx.core.eventbus.EventBus; -import io.vertx.core.spi.cluster.ClusterManager; -import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager; + public class MsgSenderVerticle extends AbstractVerticle { From f3841cec405877d9aaf747d44e3497cc8d45a9bd Mon Sep 17 00:00:00 2001 From: Prasanth P Date: Tue, 10 Aug 2021 11:52:24 -0700 Subject: [PATCH 4/6] Update README.adoc --- jbpm-examples/README.adoc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/jbpm-examples/README.adoc b/jbpm-examples/README.adoc index 5f509ff16..b579e084e 100644 --- a/jbpm-examples/README.adoc +++ b/jbpm-examples/README.adoc @@ -9,18 +9,28 @@ Process Definition can be found in :src/main/resources/io/vertx/example/jbpm/sa The link:src/main/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the junit test for running the verticle. -Additional Info +*Additional Info* jbpm-examples project will be packaged as a kjar to include jbpm artifacts(bpmn and kie-module). -To run verticles +*Run verticles* -Create a uber jar with all dependencies. pom has a maven-shade-plugin for this. -run in command line - mvn package. +Create a uber jar with all dependencies. pom file has a maven-shade-plugin for this. +To create a uber jar, run maven command - -Once the jar is created, run the vertx commands for deploying verticles. +[source,java] +---- +mvn package +---- +Once the jar is created, run the following vertx commands for deploying verticles. +[source,java] +---- vertx run io.vertx.example.jbpm.MsgSenderVerticle -cp -cluster +---- +[source,java] +---- vertx run io.vertx.example.jbpm.JbpmVerticle -cp -cluster +---- From c343be9cdb61bc95ac7901d743f9cb95db1ead78 Mon Sep 17 00:00:00 2001 From: Prasanth P Date: Tue, 10 Aug 2021 15:18:48 -0700 Subject: [PATCH 5/6] Update README.adoc --- jbpm-examples/README.adoc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jbpm-examples/README.adoc b/jbpm-examples/README.adoc index b579e084e..96b1025fa 100644 --- a/jbpm-examples/README.adoc +++ b/jbpm-examples/README.adoc @@ -4,9 +4,9 @@ This project will demonstrate the usage of jbpm to create business processes(usi The link:src/main/java/io/vertx/example/jbpm/JbpmVerticle.java[JbpmVerticle.java] shows the Verticle with embedded Jbpm. -Process Definition can be found in :src/main/resources/io/vertx/example/jbpm/sample.bpmn[sample.bpmn] +Process Definition can be found in :src/main/resources/io.vertx.example.jbpm/sample.bpmn[sample.bpmn] -The link:src/main/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the +The link:src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the junit test for running the verticle. *Additional Info* @@ -24,11 +24,14 @@ 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 From fa0740c07a5e495c3bfae09f71cd511843508d69 Mon Sep 17 00:00:00 2001 From: Prasanth P Date: Tue, 10 Aug 2021 15:22:35 -0700 Subject: [PATCH 6/6] Update README.adoc --- jbpm-examples/README.adoc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jbpm-examples/README.adoc b/jbpm-examples/README.adoc index 96b1025fa..2c209a040 100644 --- a/jbpm-examples/README.adoc +++ b/jbpm-examples/README.adoc @@ -4,10 +4,7 @@ This project will demonstrate the usage of jbpm to create business processes(usi The link:src/main/java/io/vertx/example/jbpm/JbpmVerticle.java[JbpmVerticle.java] shows the Verticle with embedded Jbpm. -Process Definition can be found in :src/main/resources/io.vertx.example.jbpm/sample.bpmn[sample.bpmn] - -The link:src/test/java/io/vertx/example/jbpm/JbpmVerticleTest.java[JbpmVerticleTest.java] shows the -junit test for running the verticle. +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*