tree: a5c35862412050dbe92939d1e45dc3b18789f07b [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.md
serverless-workflow-examples/serverless-workflow-dmn-quarkus/README.md

Kogito Serverless Workflow - DMN Example

Description

This example contains a simple workflow service that use DMN. The services are described using JSON format as defined in the CNCF Serverless Workflow specification.

The workflow expects as JSON input containing driver details and a traffic violation (see details in the Submit a request section).

The workflow uses that input to execute a decision file which evaluates if the driver should be suspended or not.

Installing and Running

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.1+ installed
  • Environment variable GRAALVM_HOME set accordingly
  • Note that GraalVM native image compilation typically requires other packages (glibc-devel, zlib-devel and gcc) to be installed too. You also need ‘native-image’ installed in GraalVM (using ‘gu install native-image’). Please refer to GraalVM installation documentation for more details.

Compile and Run in Local Dev Mode

mvn clean package quarkus:dev

Compile 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

Compile and Run using Local Native Image

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/serverless-workflow-dmn-quarkus-{version}-runner

Example Usage

Once the service is up and running, you can use the following example to interact with the service.

POST /Traffic Violation

Returns penalty information from the given inputs -- driver and violation:

Given inputs:

{
    "Driver":{"Points":2},
    "Violation":{
        "Type":"speed",
        "Actual Speed":120,
        "Speed Limit":100
    }
}

Curl command (using the JSON object above):

curl -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"Driver":{"Points":2},"Violation":{"Type":"speed","Actual Speed":120,"Speed Limit":100}}' http://localhost:8080/traffic-violation

or on Windows:

curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"Driver\":{\"Points\":2},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\":120,\"Speed Limit\":100}}" http://localhost:8080/traffic-violation

As response, penalty information is returned.

Example response:

{"workflowdata":
  {
    "Violation":{
      "Type":"speed",
      "Speed Limit":100,
      "Actual Speed":120
    },
    "Driver":{
      "Points":2
    },
    "Fine":{
      "Points":3,
      "Amount":500
    },
    "Should the driver be suspended?":"No"
  }
}