Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Automating rule-based services with Java and Kogito

June 24, 2021
Karina Varela
Related topics:
Automation and managementJavaKubernetesQuarkus
Related products:
Red Hat build of QuarkusRed Hat JBoss Enterprise Application PlatformRed Hat OpenShift

Share:

    Business automation today is a constant and critical task for organizations that seek to formalize policies and ensure that they can be executed, maintained, monitored, and applied during daily operations. This article demonstrates how to use the Kogito engine to automate business rules by implementing them in the Drools Rules Language (DRL).

    DRL is common in Drools-based projects. To start using it with Kogito, you need to understand the concept of rule units. You'll learn how to work with rule units in practice by writing a Java service that automates a piece of business logic with rule units and minimal coding. These capabilities are now part of Red Hat Process Automation Manager 7.11.x, released on June 17.

    Note: See How to deliver decision services with Kogito for more about creating a decision service with Decision Model and Notation (DMN) in Kogito and Quarkus.

    Automating business rules with Kogito

    Bringing all the maturity of Drools, Kogito is an open source project with a lightweight, fast, and cloud-native runtime engine. Developers using Kogito can expect runtime environment improvements and new a tooling set to use along with IDEs like VS Code. Starting with Process Automation Manager version 7.11.x, it is possible to use a supported version of Kogito based on version 1.5.x . You can choose between running decision services with two runtimes: The Red Hat build of Quarkus 1.11.x or Spring Boot 2.3.4.

    In Kogito, you can define business rules using Drools Rules Language or decision tables written in the XLS format. If you are familiar with decision tables, you shouldn't notice many differences when using them with Kogito. To use DRL-based rules, however, you need to get used to the concept of rule units.

    A rule unit aggregates a set of rules along with a description of the working memory that these rules will act upon, also called data sources. Kogito uses rule units to generate an executable model based on the rules, with a faster startup time. Kogito Codegen also takes advantage of Drools Rules Language queries to discover possible APIs to expose via REST, based on queries defined in the rule unit.

    Using rule units in Kogito

    We'll get started with Kogito and rule units through a simple example that defines a person and whether that person is an adult.

    Start with a POJO (plain old Java object) named Person with the following attributes:

    package org.acme.domain;
    
    public class Person {
    
        private String name;
    
        private int age;
    
        private boolean adult;
    
           // (getters and setters omitted)
    } 
    

    Next, we can define the rule unit, which we call PersonUnit. It extends the RuleUnitData class org.kie.kogito.rules:

    
    package org.acme;
    
    import org.acme.domain.Person;
    
    import org.kie.kogito.rules.DataSource;
    
    import org.kie.kogito.rules.DataStore;
    
    import org.kie.kogito.rules.RuleUnitData;
    
    public class PersonUnit implements RuleUnitData {
    
        private DataStore<Person> persons = DataSource.createStore();
    
        private int adultAge;
    
        public PersonUnit() {
    
        }
    
        //getters and setters omitted
    
    }
    
    

    Our DRL rule implementation is linked to the rule unit we have just defined by the declaration unit PersonUnit. To write the Is Adult rule, we use OOPath, a version of the standard XPath language that is designed for use with objects. It provides a succinct and readable way to work with DRL.

    
    package org.acme;
    
    unit PersonUnit; //This links this rule back to our RuleUnit
    
    import org.acme.domain.Person;
    
    rule "Is Adult"
    
    when
    
      $p: /persons[age >= 18]; //Tests the age of any Person object in the datastore persons declared in the rule unit
    
    then
    
      $p.setAdult(true);
    
    end
    query "adult" // Allows Kogito code-gen to expose a domain-driven api to search for adults.
    
      $p: /persons;
    
    end
    
    

    As this example shows, Kogito helps business automation developers create lightweight rules services quickly with Quarkus or Spring Boot, package the services traditionally or using native compilation, and even deploy them as functions with KNative on top of Kubernetes and Red Hat OpenShift. For resource planning, Process Automation Manager fully supports OptaPlanner version 8, the most recent version of this machine learning constraint-solver technology.

    Related tools and support

    If you are interested in trying out Kogito and rule units, check out these places where you can get started:

    • The OpenShift interactive learning portal for Kogito rules
    • The Kogito documentation
    • The community channels at the Kogito community, including its core contributors team.

    Note: Also see my previous article, which has more information about using Kogito decision services with Decision Model and Notation (DMN) and creating a decision service with Kogito and Quarkus.

    Conclusion

    Kogito brings back the joy for business automation developers, who can now quickly develop lightweight rules services, package them traditionally or using native compilation, and even deploy them as functions with KNative on top of Kubernetes and OpenShift. Try it out today, share your feedback, and contribute. The architectural possibilities are endless and flexible to suit on-premises or cloud environments.

    Last updated: January 22, 2024

    Related Posts

    • Deliver decision services with Kogito

    • Create your first application with Kogito

    • Kogito for Quarkus intelligent applications

    • Quarking Drools: How we turned a 13-year-old Java project into a first-class serverless component

    Recent Posts

    • Expand Model-as-a-Service for secure enterprise AI

    • OpenShift LACP bonding performance expectations

    • Build container images in CI/CD with Tekton and Buildpacks

    • How to deploy OpenShift AI & Service Mesh 3 on one cluster

    • JVM tuning for Red Hat Data Grid on Red Hat OpenShift 4

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue