|
| 1 | +# Flowable External Worker Library for Java |
| 2 | + |
| 3 | +To use Flowable together with a Java application external workers can be used. |
| 4 | +This project allows to connect a Java library to Flowable. |
| 5 | +To connect to a Flowable installation it is required [to authenticate](#authentication). |
| 6 | +With the client it is possible to specify a callback method which is called for every job executed. |
| 7 | + |
| 8 | +## Authentication |
| 9 | + |
| 10 | +There are 2 ways that the application can be authenticated with a Flowable installation. |
| 11 | + |
| 12 | +* Using HTTP Basic authentication with a provided username and password |
| 13 | +* Using HTTP Bearer authentication with a provided access token |
| 14 | + |
| 15 | +## Spring Boot Sample |
| 16 | + |
| 17 | +The following dependency needs to be added to start using Flowable workers. |
| 18 | + |
| 19 | +```xml |
| 20 | +<dependency> |
| 21 | + <groupId>org.flowable.client.spring</groupId> |
| 22 | + <artifactId>flowable-external-worker-spring-boot-starter</artifactId> |
| 23 | + <version>${flowable-worker-client.version}</version> |
| 24 | +</dependency> |
| 25 | +``` |
| 26 | + |
| 27 | +The following is an example Flowable Worker that is retrieving jobs from the `myTopic` topic |
| 28 | + |
| 29 | +```java |
| 30 | +import org.springframework.stereotype.Component; |
| 31 | + |
| 32 | +import org.flowable.external.client.AcquiredExternalWorkerJob; |
| 33 | +import org.flowable.external.worker.annotation.FlowableWorker; |
| 34 | + |
| 35 | +@Component |
| 36 | +public class ExampleWorker { |
| 37 | + |
| 38 | + @FlowableWorker(topic = "myTopic") |
| 39 | + public void processJob(AcquiredExternalWorkerJob job) { |
| 40 | + System.out.println("Executed job: " + job.getId()); |
| 41 | + } |
| 42 | + |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +Using the example above the job will be completed if the method completes successfully, and it will fail if the method throws an exception. |
| 47 | + |
| 48 | +In order to pass additional data for a failure or a completion the following example can be used: |
| 49 | + |
| 50 | +```java |
| 51 | +import org.springframework.stereotype.Component; |
| 52 | + |
| 53 | +import org.flowable.external.client.AcquiredExternalWorkerJob; |
| 54 | +import org.flowable.external.worker.annotation.FlowableWorker; |
| 55 | +import org.flowable.external.worker.WorkerResult; |
| 56 | +import org.flowable.external.worker.WorkerResultBuilder; |
| 57 | + |
| 58 | +@Component |
| 59 | +public class ExampleWorker { |
| 60 | + |
| 61 | + @FlowableWorker(topic = "myTopic") |
| 62 | + public WorkerResult processJob(AcquiredExternalWorkerJob job, WorkerResultBuilder resultBuilder) { |
| 63 | + System.out.println("Executed job: " + job.getId()); |
| 64 | + Object errorMessage = job.getVariables().get("errorMessage"); |
| 65 | + if (errorMessage != null) { |
| 66 | + return resultBuilder.failure() |
| 67 | + .message(errorMessage.toString()) |
| 68 | + .details("Error message details"); |
| 69 | + } |
| 70 | + |
| 71 | + return resultBuilder.success() |
| 72 | + .variable("message", "Job has been executed"); |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | + |
| 78 | +### Local |
| 79 | + |
| 80 | +The following properties are example how you can connect to a Flowable instance running at `http://host.docker.internal:8090` |
| 81 | + |
| 82 | +```properties |
| 83 | +flowable.external.worker.rest.base-url=http://host.docker.internal:8090 |
| 84 | +flowable.external.worker.rest.authentication.basic.username=admin |
| 85 | +flowable.external.worker.rest.authentication.basic.password=test |
| 86 | +``` |
| 87 | + |
| 88 | +### Cloud |
| 89 | + |
| 90 | +The usage with Flowable Cloud is simpler, since everything is pre-configured. |
| 91 | +However, it's required to either use the user credentials or to pre-configure a personal access token. |
| 92 | + |
| 93 | + |
| 94 | +```properties |
| 95 | +flowable.external.worker.rest.authentication.bearer.token=<personal-access-token> |
| 96 | +``` |
0 commit comments