This example demonstrates the capability of the Kogito Event-Driven Decisions AddOn: to enable, when included as dependency of a simple DMN service, to trigger evaluations of its models and receive the corresponding results via specific CloudEvents.
The source and destination of these events are two configured Kafka topics.
The main goal behind the addon is to allow Kogito DMN services to be used as part of an event processing pipeline.
You will need:
- Java 11+ installed
- Environment variable JAVA_HOME set accordingly
- Maven 3.6.2+ installed
- Docker Engine and Docker Compose 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.
Like the other Kogito AddOns, the only required step to enable it is to include it as dependency in the POM file:
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-event-driven-decisions-quarkus-addon</artifactId>
</dependency>
The version is implicitly derived from the kogito-quarkus-bom
included in the dependencyManagement
section.
The only configuration required is for the input and output topics. The Quarkus addon uses MicroProfile Reactive Messaging under the hood and must be configured accordingly.
Here is the important section of application.properties:
mp.messaging.incoming.kogito_incoming_stream.group.id=<group_id>
mp.messaging.incoming.kogito_incoming_stream.connector=smallrye-kafka
mp.messaging.incoming.kogito_incoming_stream.topic=<input_topic_name>
mp.messaging.incoming.kogito_incoming_stream.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer
mp.messaging.outgoing.kogito_outgoing_stream.group.id=<group_id>
mp.messaging.outgoing.kogito_outgoing_stream.connector=smallrye-kafka
mp.messaging.outgoing.kogito_outgoing_stream.topic=<output_topic_name>
mp.messaging.outgoing.kogito_outgoing_stream.value.serializer=org.apache.kafka.common.serialization.StringSerializer
Insert the value you need in <group_id>
, <input_topic_name>
and <output_topic_name>
. Pre-configured values already works if you follow this
guide without changes.
There's a useful docker-compose.yml in the root that starts a dedicated Kafka instance for quick tests.
Simply start it with this command from the root of the repo:
docker-compose up -d
Once everything is started you can check the data contained in your small Kafka instance via Kafdrop at http://localhost:9000/
.
mvn clean compile quarkus:dev
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
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/dmn-quarkus-example-runner
Note: This does not yet work on Windows, GraalVM and Quarkus should be rolling out support for Windows soon.
Here is an example of a input event that triggers the evaluation. Just send this payload to the configured input topic:
{
"specversion": "1.0",
"id": "a89b61a2-5644-487a-8a86-144855c5dce8",
"source": "SomeEventSource",
"type": "DecisionRequest",
"subject": "TheSubject",
"kogitodmnmodelname": "TransactionMonitoringDMN",
"kogitodmnmodelnamespace": "https://kiegroup.org/dmn/_EED47FB5-8A7C-44F3-A786-563FD2DAF015",
"data": {
"Transaction": { "transactionAmount": 9500,
"transactionCountry":"US",
"merchantType": "MERCH336",
"transactionType":"Web" ,
"transactionId":1626891159443,
"paymentMode":"savings"},
"Customer": {
"averageTransactionAmount": 300,
"riskIndex": 1.7,
"marriage": false,
"jobChange": false,
"cityChange": false,
"customerId": "CUST898920"
}
}
}