tree: cdfa5b31fe1218d82ba17bbc6de5e8222daf791f [path history] [tgz]
  1. docs/
  2. src/
  3. pom.xml
  4. README.md
kogito-quarkus-examples/process-mongodb-persistence-quarkus/README.md

Process with persistence powered by MongoDB

Description

A quickstart project that processes deals for travellers. It utilizes process composition to split the work of

  • submitting a deal
  • reviewing a deal

At the same time shows simplified version of a approval process that waits for human actor to provide review.

This example shows

  • exposing Submit Deal as public service
  • each process instance is going to be evaluated and asks for review
  • at any point in time service can be shutdown and when brought back it will keep the state of the instances

Note: The use of this example shows that the data sent to MongoDB is saved, you can shut down the application and restart it and as long as MongoDB is running after you restart you should still see the data

It utilizes MongoDB server as the backend store.

  • Process (submitDeal.bpmn)
  • Process Properties (top)
  • Process Properties (bottom)
  • Call a deal
  • Call a deal (Assignments)
  • Print review the Deal
  • Subprocess (reviewDeal.bpmn)
  • Deal Review (top)
  • Deal Review (bottom)
  • Review deal user task (top)
  • Review deal user task (botom)
  • Review deal user task (Assignments)

Infrastructure requirements

This quickstart requires an MongoDB server to be available and by default expects it to be on default port(27017) and localhost. The default database is “kogito” or you can provide the database name using property - quarkus.mongodb.database. You must set property - kogito.persistence.type=mongodb For more details you can check applications.properties.

  • MongoDB installed and running

Build and run

Prerequisites

You will need:

  • Java 17+ installed
  • Environment variable JAVA_HOME set accordingly
  • Maven 3.9.6+ installed

When using native image compilation, you will also need:

  • GraalVM 19.3+ installed
  • Environment variable GRAALVM_HOME set accordingly
  • GraalVM native image needs as well native-image extension: https://www.graalvm.org/reference-manual/native-image/
  • Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too, please refer to GraalVM installation documentation for more details.

Compile and Run in Local Dev Mode

mvn clean compile quarkus:dev

NOTE: With dev mode of Quarkus you can take advantage of hot reload for business assets like processes, rules, decision tables and java code. No need to redeploy or restart your running application.

Kogito runtimes need to be able to safely handle concurrent requests to shared instances such as process instances, tasks, etc. This feature is optional and can be pluggable with persistence using the following property and value to the src/main/resources/application.properties file.

kogito.persistence.optimistic.lock=true 

Additionally, you can use below commands to set this property at runtime and build and run the application

mvn clean compile quarkus:dev -Dkogito.persistence.optimistic.lock=true

or

mvn clean package
java -Dkogito.persistence.optimistic.lock=true -jar target/quarkus-app/quarkus-run.jar

Package and Run in JVM mode

mvn clean package
java -jar target/quarkus-app/quarkus-run.jar

or on windows

mvn clean package
java -jar target\quarkus-app\quarkus-run.jar

Package and Run using Local Native Image

Note that the following configuration property needs to be added to application.properties in order to enable automatic registration of META-INF/services entries required by the workflow engine:

quarkus.native.auto-service-loader-registration=true

Note that this requires GRAALVM_HOME to point to a valid GraalVM installation

mvn clean package -Pnative

To run the generated native executable, generated in target/, execute

./target/process-mongodb-persistence-quarkus-runner

OpenAPI (Swagger) documentation

Specification at swagger.io

You can take a look at the OpenAPI definition - automatically generated and included in this service - to determine all available operations exposed by this service. For easy readability you can visualize the OpenAPI definition file using a UI tool like for example available Swagger UI.

In addition, various clients to interact with this service can be easily generated using this OpenAPI definition.

When running in either Quarkus Development or Native mode, we also leverage the Quarkus OpenAPI extension that exposes Swagger UI that you can use to look at available REST endpoints and send test requests.

Submit a deal

To make use of this application it is as simple as putting a sending request to http://localhost:8080/deals with following content

{
"name" : "my fancy deal",
"traveller" : {
  "firstName" : "John",
  "lastName" : "Doe",
  "email" : "jon.doe@example.com",
  "nationality" : "American",
  "address" : {
  	"street" : "main street",
  	"city" : "Boston",
  	"zipCode" : "10005",
  	"country" : "US" }
  }
}

Complete curl command can be found below:

curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"name" : "my fancy deal", "traveller" : { "firstName" : "John", "lastName" : "Doe", "email" : "jon.doe@example.com", "nationality" : "American","address" : { "street" : "main street", "city" : "Boston", "zipCode" : "10005", "country" : "US" }}}' http://localhost:8080/deals

this will then trigger the review user task that you can work with.

Get review task for given deal

You can display all active reviews of deals by running

curl http://localhost:8080/usertasks/instance?user=john

Complete review task for given deal

Last but not least you can complete review user task by

curl -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d '{"transitionId":"complete","data":{"review" : "very good work"}}' http://localhost:8080/usertasks/instance/{tuuid}/transition?user=john

where tuuid is the id of the user task you want to complete

  • Review Log should look similar to
Review of the deal very good work for traveller Doe

You can also query the process instance information and model variables from the database and review the same using tools like MongoDB Compass, download community version from below link https://www.mongodb.com/try/download/compass