tree: c5a29d8bce06adb10e84fe801ea6dd372d68789b [path history] [tgz]
  1. dmn-quarkus-consumer-example/
  2. dmn-quarkus-resource-jar/
  3. pom.xml
  4. README.md
kogito-quarkus-examples/dmn-resource-jar-quarkus-example/README.md

DMN + Quarkus example with model included in different jar

Description

A simple DMN service to evaluate a model (traffic violation) that is imported from a different jar. It also features the usage of custom DMN profiles, imported from a dependency and declared inside the application.properties file.

Demonstrates DMN on Kogito capabilities, including REST interface code generation.

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 install
cd ./dmn-quarkus-consumer-example
mvn quarkus:dev

(This requires a previous installation of dmn-quarkus-resource-jar)

Package and Run in JVM mode

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

or on Windows

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

Package 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 ./dmn-quarkus-consumer-example/target/, execute

./dmn-quarkus-consumer-example/target/dmn-quarkus-consumer-example-runner

Note: This does not yet work on Windows, GraalVM and Quarkus should be rolling out support for Windows soon.

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.

Test DMN Model using Maven

Validate the functionality of DMN models before deploying them into a production environment by defining test scenarios in Test Scenario Editor.

To define test scenarios you need to create a .scesim file inside your project and link it to the DMN model you want to be tested. Run all Test Scenarios, executing:

cd ./dmn-quarkus-consumer-example
mvn clean test

See results in surefire test report target/surefire-reports

(This requires a previous installation of dmn-quarkus-resource-jar)

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%20Violation

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%20Violation

As response, penalty information is returned.

Example response:

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

The difference from the dmn-quarkus-example is that, in the current one, the Traffic Model.dml is defined in a different jar.