From 9f33f42d5b0bd9f52c6eda2b8b2535b8222032b2 Mon Sep 17 00:00:00 2001 From: Tobias Schaefer Date: Tue, 9 Mar 2021 17:41:08 +0100 Subject: [PATCH] Move external task process to the main example project and remove example-external-task-process which is no longer needed. --- example-external-task-process/README.md | 21 ---- example-external-task-process/build.gradle | 49 -------- .../gradle.properties | 0 .../ExternalTaskProcessApplication.java | 25 ---- .../process/FetchAndLockContextFactory.java | 38 ------ .../src/main/resources/application.yml | 6 - .../main/resources/external-task-process.bpmn | 71 ------------ .../src/main/resources/logback.xml | 15 --- .../ExternalTaskProcessApplicationTest.kt | 19 --- .../bpm/externaltask/process/ProcessTest.kt | 43 ------- .../worker/ExternalTaskWorker.java | 22 ++-- micronaut-camunda-bpm-example/README.md | 4 +- .../calculation/CreateItemDelegate.java | 14 +-- .../calculation/PrintResultDelegate.java | 8 +- .../src/main/resources/calculation.bpmn | 109 ++++++++++++++++++ .../bpm/example/CamundaControllerTest.java | 2 +- settings.gradle | 1 - 17 files changed, 134 insertions(+), 313 deletions(-) delete mode 100644 example-external-task-process/README.md delete mode 100644 example-external-task-process/build.gradle delete mode 100644 example-external-task-process/gradle.properties delete mode 100644 example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ExternalTaskProcessApplication.java delete mode 100644 example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/FetchAndLockContextFactory.java delete mode 100644 example-external-task-process/src/main/resources/application.yml delete mode 100644 example-external-task-process/src/main/resources/external-task-process.bpmn delete mode 100644 example-external-task-process/src/main/resources/logback.xml delete mode 100644 example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ExternalTaskProcessApplicationTest.kt delete mode 100644 example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ProcessTest.kt rename example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ItemDelegate.java => micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/CreateItemDelegate.java (74%) rename example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ResultDelegate.java => micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/PrintResultDelegate.java (78%) create mode 100644 micronaut-camunda-bpm-example/src/main/resources/calculation.bpmn diff --git a/example-external-task-process/README.md b/example-external-task-process/README.md deleted file mode 100644 index 42c52918..00000000 --- a/example-external-task-process/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# example-external-task-process - -Example application for running the Micronaut-Camunda-Integration with -external tasks. Use in conjunction with example-external-task-worker. - -example-external-task-process starts a process creating an external task -every 5 seconds. - -see also [README](../example-external-task-worker/README.md) for example-external-task-worker - -## Start the application - -Start process application with - -`../gradlew run` - -## REST Service for External Task Worker - -The necessary REST services needed for the external task worker are exposed -manually in MyExternalTaskRestService as the Camunda REST interface isn't -exposed by the micronaut-camunda-bpm-feature now. diff --git a/example-external-task-process/build.gradle b/example-external-task-process/build.gradle deleted file mode 100644 index 53b262e2..00000000 --- a/example-external-task-process/build.gradle +++ /dev/null @@ -1,49 +0,0 @@ -plugins { - id("com.github.johnrengelman.shadow") - id("io.micronaut.application") - - // used for tests - id("org.jetbrains.kotlin.jvm") - id("org.jetbrains.kotlin.kapt") - id("org.jetbrains.kotlin.plugin.allopen") -} - -group = "info.novatec" - -micronaut { - runtime("jetty") - testRuntime("junit5") - processing { - incremental(true) - annotations("micronaut.camunda.bpm.externaltask.process.*") - } -} - -dependencies { - implementation(project(":micronaut-camunda-bpm-feature")) - implementation("io.micronaut:micronaut-runtime") - // needed to initialize FetchAndLockContextListener - implementation("org.camunda.bpm:camunda-engine-rest-jaxrs2:$camundaVersion") - - // Dependency is currently needed if the build is executed with the Netty runtime in the CI's matrix build - compileOnly("javax.servlet:javax.servlet-api:4.0.1") - - runtimeOnly("ch.qos.logback:logback-classic") - runtimeOnly("com.h2database:h2") - - kaptTest platform("io.micronaut:micronaut-bom:$micronautVersion") - kaptTest("io.micronaut.data:micronaut-data-processor") - kapt("io.micronaut:micronaut-inject-java:$micronautVersion") - - testImplementation("org.camunda.bpm.assert:camunda-bpm-assert:8.0.0") - testImplementation("org.assertj:assertj-core") -} - -application { - mainClass.set("info.novatec.micronaut.camunda.externaltask.process.ExternalTaskProcessApplication") -} - -java { - sourceCompatibility = JavaVersion.toVersion("1.8") - targetCompatibility = JavaVersion.toVersion("1.8") -} diff --git a/example-external-task-process/gradle.properties b/example-external-task-process/gradle.properties deleted file mode 100644 index e69de29b..00000000 diff --git a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ExternalTaskProcessApplication.java b/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ExternalTaskProcessApplication.java deleted file mode 100644 index 40dd0744..00000000 --- a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ExternalTaskProcessApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020-2021 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package info.novatec.micronaut.camunda.externaltask.process; - -import io.micronaut.runtime.Micronaut; - -public class ExternalTaskProcessApplication { - - public static void main(String[] args) { - Micronaut.run(ExternalTaskProcessApplication.class, args); - } -} diff --git a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/FetchAndLockContextFactory.java b/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/FetchAndLockContextFactory.java deleted file mode 100644 index 6f79200d..00000000 --- a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/FetchAndLockContextFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2021 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package info.novatec.micronaut.camunda.externaltask.process; - -import io.micronaut.context.annotation.Bean; -import io.micronaut.context.annotation.Context; -import io.micronaut.context.annotation.Factory; -import org.camunda.bpm.engine.rest.impl.FetchAndLockContextListener; - -/** - * Initialize default FetchAndLockContextListener so that ExternalWorker can fetch Tasks and lock them to be processed. - */ -@Factory -class FetchAndLockContextFactory { - - @Context - @Bean(preDestroy = "contextDestroyed") - FetchAndLockContextListener fetchAndLockContextListener() { - FetchAndLockContextListener fetchAndLockContextListener = new FetchAndLockContextListener(); - // passing null value is fine as long as no unique workers are needed - // for details check org.camunda.bpm.engine.rest.impl.FetchAndLockHandlerImpl.contextInitialized - fetchAndLockContextListener.contextInitialized(null); // starts the listener - return fetchAndLockContextListener; - } -} diff --git a/example-external-task-process/src/main/resources/application.yml b/example-external-task-process/src/main/resources/application.yml deleted file mode 100644 index dad8749e..00000000 --- a/example-external-task-process/src/main/resources/application.yml +++ /dev/null @@ -1,6 +0,0 @@ -micronaut: - application: - name: micronaut-external-task-process -camunda: - rest: - enabled: true diff --git a/example-external-task-process/src/main/resources/external-task-process.bpmn b/example-external-task-process/src/main/resources/external-task-process.bpmn deleted file mode 100644 index de6a4e56..00000000 --- a/example-external-task-process/src/main/resources/external-task-process.bpmn +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - Flow_1sgpapd - - - - SequenceFlow_0zvob4z - - R99/PT5S - - - - SequenceFlow_0zvob4z - SequenceFlow_17q8g0e - - - - SequenceFlow_17q8g0e - SequenceFlow_0eg8114 - - - - SequenceFlow_0eg8114 - Flow_1sgpapd - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/example-external-task-process/src/main/resources/logback.xml b/example-external-task-process/src/main/resources/logback.xml deleted file mode 100644 index 82218708..00000000 --- a/example-external-task-process/src/main/resources/logback.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - false - - - %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n - - - - - - - diff --git a/example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ExternalTaskProcessApplicationTest.kt b/example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ExternalTaskProcessApplicationTest.kt deleted file mode 100644 index 9f0bb98e..00000000 --- a/example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ExternalTaskProcessApplicationTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package info.novatec.micronaut.camunda.bpm.externaltask.process - -import io.micronaut.runtime.EmbeddedApplication -import io.micronaut.test.extensions.junit5.annotation.MicronautTest -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test -import javax.inject.Inject - -@MicronautTest -class ExternalTaskProcessApplicationTest { - - @Inject - lateinit var application: EmbeddedApplication<*> - - @Test - fun testItWorks() { - assertTrue(application.isRunning) - } -} \ No newline at end of file diff --git a/example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ProcessTest.kt b/example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ProcessTest.kt deleted file mode 100644 index 04f44699..00000000 --- a/example-external-task-process/src/test/kotlin/info/novatec/micronaut/camunda/bpm/externaltask/process/ProcessTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2021 original authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package info.novatec.micronaut.camunda.bpm.externaltask.process - -import io.micronaut.test.extensions.junit5.annotation.MicronautTest -import org.camunda.bpm.engine.RuntimeService -import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.* -import org.junit.jupiter.api.Test -import javax.inject.Inject - -@MicronautTest -class ProcessTest { - - @Inject - lateinit var runtimeService: RuntimeService - - @Test - fun happyPath() { - val processInstance = runtimeService.startProcessInstanceByKey("externalTaskProcessExample") - assertThat(processInstance).isStarted - assertThat(processInstance).isWaitingAt("externalTask").externalTask().hasTopicName("my-topic") - complete(externalTask(), withVariables("approved", true)) - assertThat(processInstance).hasPassed( - "createItem", - "externalTask", - "logResult" - ) - } - -} \ No newline at end of file diff --git a/example-external-task-worker/src/main/java/info/novatec/micronaut/camunda/externaltask/worker/ExternalTaskWorker.java b/example-external-task-worker/src/main/java/info/novatec/micronaut/camunda/externaltask/worker/ExternalTaskWorker.java index 55ef5cc7..be414802 100644 --- a/example-external-task-worker/src/main/java/info/novatec/micronaut/camunda/externaltask/worker/ExternalTaskWorker.java +++ b/example-external-task-worker/src/main/java/info/novatec/micronaut/camunda/externaltask/worker/ExternalTaskWorker.java @@ -15,36 +15,35 @@ */ package info.novatec.micronaut.camunda.externaltask.worker; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - import io.micronaut.runtime.event.annotation.EventListener; import io.micronaut.runtime.server.event.ServerStartupEvent; import org.camunda.bpm.client.ExternalTaskClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Singleton; +import java.util.HashMap; +import java.util.Map; @Singleton public class ExternalTaskWorker { - private final static Logger log = Logger.getLogger(ExternalTaskWorker.class.getName()); + private static final Logger log = LoggerFactory.getLogger(ExternalTaskWorker.class); + + private static final String BASE_URL = "http://localhost:8080/engine-rest"; @EventListener void onStartup(ServerStartupEvent event) { - log.info("Starting ExternalTaskClient"); + log.info("Starting ExternalTaskClient connected to {}", BASE_URL); ExternalTaskClient client = ExternalTaskClient.create() - .baseUrl("http://localhost:8080/engine-rest") + .baseUrl(BASE_URL) .asyncResponseTimeout(10000) // long polling timeout .build(); - // subscribe to an external task topic as specified in the process client.subscribe("my-topic") .lockDuration(1000) // the default lock duration is 20 seconds, but you can override this .handler((externalTask, externalTaskService) -> { - // Put your business logic here - // Get a process variable Integer item = externalTask.getVariable("itemNumber"); Integer value = externalTask.getVariable("itemValue"); @@ -54,10 +53,9 @@ void onStartup(ServerStartupEvent event) { Map variables = new HashMap<>(); variables.put("approved", approved); - // Complete the task externalTaskService.complete(externalTask, variables); - log.info("Finished item " + item + " with Value " + value); + log.info("Finished item {} with value {}", item, value); }) .open(); } diff --git a/micronaut-camunda-bpm-example/README.md b/micronaut-camunda-bpm-example/README.md index d5940737..51e349ba 100644 --- a/micronaut-camunda-bpm-example/README.md +++ b/micronaut-camunda-bpm-example/README.md @@ -38,9 +38,11 @@ The Camunda REST API is available at the context path `/engine-rest`, e.g. `GET The following HTTP endpoints have been implemented as examples: * `GET http://localhost:8080/example/name` will return "default" as the name of the default process engine. -* `GET http://localhost:8080/example/definitions` will return "HelloWorld" as the currently deployed process model. +* `GET http://localhost:8080/example/definitions` will return "Calculation,HelloWorld,Onboarding" as the currently deployed process models. * `POST http://localhost:8080/example/onboarding/cancel/OnStartup` can be called to cancel an Onboarding instance by the business key "OnStartup". Further calls will fail (unless a new process instance is created manually via the Tasklist with the menu item "Start process"). +If you start `ExternalTaskWorkerApplication` from the sub-module `example-external-task-worker` the external worker will process the external tasks which otherwise timeout after 10 seconds. + ## Persistent Database By default, the example app will use an H2 in-memory database which is created on application start-up. If you need a diff --git a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ItemDelegate.java b/micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/CreateItemDelegate.java similarity index 74% rename from example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ItemDelegate.java rename to micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/CreateItemDelegate.java index 77a95a2a..049d031b 100644 --- a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ItemDelegate.java +++ b/micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/CreateItemDelegate.java @@ -13,30 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package info.novatec.micronaut.camunda.externaltask.process; +package info.novatec.micronaut.camunda.bpm.example.calculation; -import java.util.concurrent.ThreadLocalRandom; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Singleton; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicInteger; @Singleton -public class ItemDelegate implements JavaDelegate { +public class CreateItemDelegate implements JavaDelegate { - private static final Logger log = LoggerFactory.getLogger(ItemDelegate.class); + private static final Logger log = LoggerFactory.getLogger(CreateItemDelegate.class); - private final AtomicInteger lastCount = new AtomicInteger(0); + private final AtomicInteger count = new AtomicInteger(0); @Override public void execute(DelegateExecution delegateExecution) { int itemValue = ThreadLocalRandom.current().nextInt(0, 1001); delegateExecution.setVariable("itemValue", itemValue); - int itemNumber = lastCount.incrementAndGet(); + int itemNumber = count.incrementAndGet(); delegateExecution.setVariable("itemNumber", itemNumber); - log.debug("Process Instance for item {} with Value {} running.", itemNumber, itemValue); + log.info("Process instance for item {} with value {} running.", itemNumber, itemValue); } } diff --git a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ResultDelegate.java b/micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/PrintResultDelegate.java similarity index 78% rename from example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ResultDelegate.java rename to micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/PrintResultDelegate.java index 6956b922..a315b1e8 100644 --- a/example-external-task-process/src/main/java/info/novatec/micronaut/camunda/externaltask/process/ResultDelegate.java +++ b/micronaut-camunda-bpm-example/src/main/java/info/novatec/micronaut/camunda/bpm/example/calculation/PrintResultDelegate.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package info.novatec.micronaut.camunda.externaltask.process; +package info.novatec.micronaut.camunda.bpm.example.calculation; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; @@ -23,13 +23,13 @@ import javax.inject.Singleton; @Singleton -public class ResultDelegate implements JavaDelegate { +public class PrintResultDelegate implements JavaDelegate { - private static final Logger log = LoggerFactory.getLogger(ResultDelegate.class); + private static final Logger log = LoggerFactory.getLogger(PrintResultDelegate.class); @Override public void execute(DelegateExecution execution) { - log.info("Item {} with value {} approved {}", + log.info("Process instance for item {} with value {} is approved={}", execution.getVariable("itemNumber"), execution.getVariable("itemValue"), execution.getVariable("approved")); diff --git a/micronaut-camunda-bpm-example/src/main/resources/calculation.bpmn b/micronaut-camunda-bpm-example/src/main/resources/calculation.bpmn new file mode 100644 index 00000000..dca6690a --- /dev/null +++ b/micronaut-camunda-bpm-example/src/main/resources/calculation.bpmn @@ -0,0 +1,109 @@ + + + + + + Flow_1p2h80x + + + + SequenceFlow_0fxbboj + + * * * * * ? + + + + SequenceFlow_0fxbboj + SequenceFlow_1uip4un + + + + SequenceFlow_1uip4un + Flow_0kvupiu + + + Flow_09cr6sc + + PT10S + + + + Flow_09cr6sc + + + + Flow_0kvupiu + Flow_1p2h80x + + + + This makes sure that we don't have more than two instances running if the job executor runs every five seconds (default) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/micronaut-camunda-bpm-example/src/test/java/info/novatec/micronaut/camunda/bpm/example/CamundaControllerTest.java b/micronaut-camunda-bpm-example/src/test/java/info/novatec/micronaut/camunda/bpm/example/CamundaControllerTest.java index 4b762630..937d6769 100644 --- a/micronaut-camunda-bpm-example/src/test/java/info/novatec/micronaut/camunda/bpm/example/CamundaControllerTest.java +++ b/micronaut-camunda-bpm-example/src/test/java/info/novatec/micronaut/camunda/bpm/example/CamundaControllerTest.java @@ -45,6 +45,6 @@ void definitions() { HttpRequest request = HttpRequest.GET("/definitions"); String body = client.toBlocking().retrieve(request); - assertEquals("HelloWorld,Onboarding", body); + assertEquals("Calculation,HelloWorld,Onboarding", body); } } diff --git a/settings.gradle b/settings.gradle index b46ad6df..b76f8a22 100644 --- a/settings.gradle +++ b/settings.gradle @@ -14,5 +14,4 @@ include ':micronaut-camunda-bpm-feature' include ':micronaut-camunda-bpm-example' include ':micronaut-camunda-bpm-feature:transactional-test-data-jdbc' include ':micronaut-camunda-bpm-feature:jetty-webapp-and-rest' -include ':example-external-task-process' include ':example-external-task-worker'