Skip to content

Commit

Permalink
Move external task process to the main example project and remove exa…
Browse files Browse the repository at this point in the history
…mple-external-task-process which is no longer needed.
  • Loading branch information
tobiasschaefer authored and jenshb committed Mar 10, 2021
1 parent c943293 commit 9f33f42
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 313 deletions.
21 changes: 0 additions & 21 deletions example-external-task-process/README.md

This file was deleted.

49 changes: 0 additions & 49 deletions example-external-task-process/build.gradle

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions example-external-task-process/src/main/resources/logback.xml

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -54,10 +53,9 @@ void onStartup(ServerStartupEvent event) {
Map<String, Object> 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();
}
Expand Down
4 changes: 3 additions & 1 deletion micronaut-camunda-bpm-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9f33f42

Please sign in to comment.