Get Started With Cloud-Native Decision Automation on Quarkus
Learn how to automate decisions using Quarkus and Kogito.
Join the DZone community and get the full member experience.
Join For FreeThis article will guide you through creating a decision application based on Quarkus and trying out the business modeling in VSCode. You will experience hot reload of business assets during development and validate your decisions.
Development of decision automation solutions has never been easier thanks to DMN (Decision Model and Notation), Kogito, and Quarkus. Kogito is designed from the ground up to run on cloud infrastructure at scale. If you think about business automation, think about the cloud — as this is where your business logic lives these days. By taking advantage of the latest technologies (Quarkus, KNative, and so on), you get amazingly fast boot times and instant scaling on orchestration platforms like OpenShift.
INFO: This article is part of a larger workshop. In case you're interested in learning more, check out the open and free guided workshop. The workshop includes guides on event-driven decision services, serverless decisions, and more.
Get Started With Decision Services
The best way to learn is to exercise. You can follow the steps below to experience the start of a new decision service, experience the flow during development time, and test your service using unit testing and the automatically generated REST endpoints.
Feel free to go through the exercise while following the explanation:
Prerequisites
Install Visual Studio Code IDE.
Install VSCode Language Support for Java and Red Hat Business Automation Bundle in VSCode.
You will need JDK 11.
You will also need Maven.
Create a New Decision Project With Quarkus and Kogito
In order to create a new decision project based on Quarkus, we can use a Maven archetype to generate the Quarkus based project with the required dependencies for our decision application.
- Navigate to a folder of your preference, and run the following command. Maven will create a new project with the name
decision-lab01
.
mvn io.quarkus.platform:quarkus-maven-plugin:2.8.2.Final:create \ -DprojectGroupId=org.acme \ -DprojectArtifactId=decision-lab01 \ -Dextensions="kogito-quarkus-decisions,quarkus-smallrye-openapi,quarkus-resteasy-jackson"
Examine the Project and Decision
Let’s open the project so we can look at its structure and files. In your terminal, you can open the project using the VScode. (You can use the code command in your CLI, as in code decision-lab01
.
In your project, you will find:
- A DMN sample,
pricing.dmn
. This decision determines a base price quotation based on criterias like age and occurrence of previous incidents. jUnit test
PricingTest.java
. This jUnit tests the REST endpoint that is generated automatically by Kogito. Further on the lab, we will work with the Test Scenario, a graphical tool that allows users to unit test the decision model.
Running the Project
It’s time to try out this project. To make things easier, you can use the Integrated Terminal feature in VSCode.
Open the integrated terminal in VSCode by pressing
cmd+shift+p
orctrl+shift+p
.Then, search for New Terminal and select it. See below:
In the recently opened integrated terminal, you can start the application.
Start the application in dev mode:
mvn quarkus:dev
- Open your browser and access http://localhost:8080/q/swagger-ui/
You should see three REST endpoints that were automatically generated by Kogito.
Select the POST request for pricing and click on the Try it out button.
You can use the following JSON as the Request Input to validate the decision about whether the driver should be suspended or not:
{ "Age": 47, "Previous incidents?": false }
The output should show the final decision Base Price but also the values of the input nodes. If there were more decisions made in this processing, the outputs would also be outputted as a result.
Updating the Decision
When using the Kogito extension with Quarkus, you can also take advantage of the hot reload features during the development of your decision. Let’s give it a try.
Still with the server running go back to the decision project in VSCode.
Open the
pricing.dmn
decision file, and select theBase Price
node. Click on the edit button.
Now, let’s change our business rule where the base price for people over 21 and without previous incidents should cost 400 instead of 500.
- On the literal expression, change the number to 400.
Save the DMN file.
Go back to your browser and click on "Execute" to execute the exact same request.
Check the response and confirm that — different from the first decision — the cost for the insurance is now 400.
Remember to also update the unit test src/test/java/org/acme/PricingTest.java
to match the new value of 400, or to revert the value back to 500 so it matches the unit tests.
Awesome! You've implemented our first DMN decision service in Kogito, used the hot/live reload capabilities of Quarkus, and seen how these changes are immediately reflected in the service endpoint. Finally, you've sent a RESTful request to our DMN decision microservice and saw cloud-native decisioning with DMN in action.
Conclusion
This is a nice first exercise where developers can get a feel for the dev experience when using Quarkus plus decision automation extensions. This technology set gives users the best of Quarkus capabilities like ultra-lightweight applications, fast startup time, native compilation (using Mandrel or GraalVM), and increased developer productivity — including hot reload features for business assets.
Opinions expressed by DZone contributors are their own.
Comments