Kogito Examples

repository·main·Indexed 43 days ago

https://github.com/apache/incubator-kie-kogito-examples

A collection of practical examples for Drools, jBPM, and Kogito technologies. This repository showcases use cases, features, and implementation patterns for the Apache KIE community, including DMN and DRL integration within BPMN processes using Quarkus and Spring Boot.

Tokens
104.6K
Snippets
371
Records
485
Agent score
54%

What's inside Kogito Examples

  1. Overview of Process with Knative Eventing Quickstart

    main

    This project demonstrates how to integrate Kogito processes and rules with Knative Eventing. It follows a pattern where the application consumes events from a Knative Eventing broker to trigger new process instances.

    Workflow Logic:

    1. Consumes JSON traveller information from a Knative broker.
    2. Starts a process instance for each event.
    3. Processes the traveller using business rules.
    4. Success Path: Logs the information and sends updated traveller data to the Knative broker.
    5. Failure Path: Logs the information and emits a skiptraveller event to the Knative broker.
  2. Overview of Process with Kafka Quickstart

    main

    This project demonstrates how to integrate Kogito processes and rules with Apache Kafka. The workflow follows this pattern:

    1. Consume Events: The application listens to a Kafka topic for incoming events.
    2. Start Process: For each event, a new Kogito process instance is started using JSON traveller information.
    3. Rule Processing: The traveller is processed by business rules.
    4. Outcome Handling:
      • Success: If processed successfully, the information is logged and an updated message is sent to a different Kafka topic.
      • Failure: If not processed, the information is logged and the process instance finishes without sending a reply to Kafka.
  3. Overview of Process with Kafka Example

    main

    This project demonstrates how to integrate Kogito processes and rules with Apache Kafka. It uses a CloudEvent-based workflow to process traveller information.

    Workflow Logic:

    1. Consume: The application listens to a Kafka topic for traveller events in JSON format.
    2. Process: For each event, a new Kogito process instance is started. The traveller data is evaluated by business rules.
    3. Branching:
      • Success: If the traveller is successfully processed, the information is logged and a message is sent to the processedtravellers topic.
      • Failure: If not processed, the information is logged and a message is sent to the cancelledtravellers topic.

    Infrastructure Requirements:

    • An Apache Kafka server must be available (defaulting to localhost:9092).
  4. Overview of the Sample Onboarding Services Example

    main

    This example demonstrates building a complete onboarding solution by orchestrating multiple independent services based on business processes and decisions.

    The architecture consists of three services:

    • onboarding: The main entry point for starting new employee onboarding (contains 3 business processes).
    • hr: A decision service for HR-related activities using DRL rules.
    • payroll: A decision service for payroll-related activities using DMN.

    Users interact primarily with the onboarding service, which coordinates calls to the hr and payroll services.

  5. Overview of the Kogito Travel Agency Tutorial

    main

    The Kogito Travel Agency tutorial is an incremental workshop designed to teach how to build a software system for a startup travel agency using Kogito. The tutorial is structured into separate folders, where each version builds upon the previous one, allowing developers to start at any stage of complexity.

    Key versions include:

    • Base version (basic): A single service handling all business and decision logic for booking flights and hotels.
    • Extended version (extended): A multi-service architecture consisting of two services (Travel Agency and Visa services) that include business and decision logic. This version includes data persistence and requires a PostgreSQL server.
  6. Overview of Sample Onboarding Services

    main

    This example demonstrates a complete onboarding solution built using multiple services that combine business processes and decisions. It consists of three independent services:

    • onboarding: The main Spring Boot service that serves as the entry point for onboarding new employees via a single REST endpoint. It uses three business processes (one main and two sub-processes) to coordinate work.
    • hr: A decision service (implemented in Quarkus) responsible for HR-related activities using DRL rules.
    • payroll: A decision service (implemented in Quarkus) responsible for payroll-related activities using DMN.

    Users typically interact only with the onboarding service, which orchestrates calls to the hr and payroll services to complete the process.

  7. Run Process Spring Boot Performance tests

    main

    This project provides BPMN processes designed for manual throughput testing of Spring Boot performance. The processes use a script to invoke Thread.sleep for a specified delay and publish a message to a _done_ channel upon completion.

    There are three distinct ways to trigger these processes:

    1. REST invocation: Use test.bpmn2.
    2. Kafka message (channel _test_): Use kafkaTest.bpmn2.
    3. Kafka message (channel _test2_): Use kafkaTestOtherChannel.bpmn2.

    Note: This project requires an Apache Kafka cluster. You can configure the Kafka broker and topic settings in application.properties.

  8. Use the Decision Table Listener with Kogito and Quarkus

    main

    This example demonstrates how to implement semantic asynchronous evaluation of AfterEvaluateDecisionTableEvents by leveraging Quarkus capabilities. It is an extension of the dmn-quarkus-listener example and focuses on handling decision table evaluation events asynchronously.

    To use this pattern, you should integrate Kogito with Quarkus to listen for specific DMN (Decision Model and Notation) decision table events and process them using Quarkus's asynchronous event handling mechanisms.

  9. Understand Kogito runtime metrics dashboards

    main

    Kogito exports two types of dashboards that can be used in Grafana:

    1. Operational Dashboards: Generated for both DMN and DRL endpoints. They track:

      • Total number of requests.
      • Average requests per minute.
      • Quantiles for request elapsed time.
      • Exception details.
    2. Domain Specific Dashboards: Generated only for DMN endpoints. They provide graphs based on the decision output type:

      • Number: Shows quantiles for the metric on a 3-minute sliding window.
      • Boolean/String: Shows the number of occurrences for each output (10-minute average).

    By default, the application exposes metrics at the /metrics endpoint for Prometheus to scrape.

  10. Map Process Variables to DMN Data Types using Jackson

    main

    When integrating BPMN processes with DMN decisions, you must ensure your Java POJOs align with the DMN data structure. If DMN attribute names contain spaces or follow naming conventions different from Java (e.g., Speed Limit instead of speedLimit), use Jackson annotations to bridge the gap.

    For example, in the Violation class, use @JsonProperty to map a Java field to a DMN attribute with spaces.

    // Example mapping for a DMN attribute with spaces
    public class Violation {
        @JsonProperty("Speed Limit")
        private double speedLimit;
        // ...
    }
  11. How Kogito Event-Driven Predictions work with PMML

    main

    The Kogito Event-Driven Predictions AddOn allows PMML models to be used in an event processing pipeline.

    1. Input: The service listens to a configured Kafka topic for CloudEvents. The event must include a kogitopmmlmodelname field matching the PMML model name and a data field containing the query input.
    2. Processing: Kogito triggers the evaluation of the specified PMML model using the provided data.
    3. Output: The result is emitted as a CloudEvent to a configured output Kafka topic. The output event contains the model name and a data field with the prediction results.
    // Example Input Event
    {
      "specversion": "1.0",
      "id": "a89b61a2-5644-487a-8a86-144855c5dce8",
      "source": "SomeEventSource",
      "type": "PredictionRequest",
      "subject": "TheSubject",
      "kogitopmmlmodelname": "LinReg",
      "data": {
        "fld1": 3.0,
        "fld2": 2.0,
        "fld3": "y"
      }
    }
    
    // Example Output Event
    {
      "specversion": "1.0",
      "id": "d54ace84-6788-46b6-a359-b308f8b21778",
      "source": "LinReg",
      "type": "PredictionResponse",
      "subject": "TheSubject",
      "kogitopmmlmodelname": "LinReg",
      "data": {
        "fld4": 52.5
      }
    }