Difficulty: beginner
Estimated Time: 10 minutes

In this scenario, you will learn how to implement process and workflow logic with CDI beans in Kogito.


BPMN2 Service Task and CDI

The BPMN2 specification defines the Service Task, an activity node used to invoke an automated application (or service) to execute a task. In Kogito, a Service Task can be implemented using a CDI bean (Quarkus) or a Spring bean (Spring Boot). In this scenario we will demonstrate this functionality using Quarkus.

Context & Dependency Injection (CDI) support allows developers to easily create process and workflow logic, in a standard Java way for building application logic. Developers can focus on developing business logic, rather than having to learn new frameworks and extensions for building process logic. These CDI beans can in their turn be injected with other logic (e.g. Camel for integration, JPA for persistence, SmallRye Reactive Messaging for messaging, etc.).

Other possibilities

Learn more at kogito.kie.org, or just drive on and get hands-on!

In this scenario, you learned how to implement the logic of a Kogito BPMN2 Service Task with a CDI bean. A foundational aspect of Kogito is that it is developer focussed. By integrating with various Java standards and de-facto standards, Kogito allows developers of business applications to use their existing skills and tools to build cloud-native process, worklfow, decision and rules applications.

Additional Resources

If you’re interested in helping continue to improve Kogito, using Kogito to develop applications, or if you’re just curious about it, please check out these links:

Kogito Service Tasks and CDI

Step 1 of 3

Step 1

In this step, you will create the Kogito application skeleton.

The Project

You start with a basic Maven-based Kogito application which has been generated from the Kogito Maven Archetype.

The Application You Will Build

The application is a simple text processor application that will convert the passed text to uppercase.

You will implement logic that converts the text to uppercase in a CDI bean.

Let's get started.

Create a basic project

The easiest way to create a new Kogito project is to execute the Maven command below by clicking on it:

mvn archetype:generate \ -DinteractiveMode=false \ -DarchetypeGroupId=org.kie.kogito \ -DarchetypeArtifactId=kogito-quarkus-archetype \ -DarchetypeVersion=0.9.0 \ -DgroupId=org.acme \ -DartifactId=service-task-cdi \ -Dversion=1.0-SNAPSHOT

This will use the Kogito Maven Archetype and generate a basic Maven project for you in the service-task-cdi subdirectory.

BPMN2 Process Definition

The default Kogito application contains a sample process called test-process.bpmn2. We will use this file as the base of our project.

Click on the following link to open the [Kogito Online Tooling] with our test process: https://kiegroup.github.io/kogito-online/?file=https://raw.githubusercontent.com/kiegroup/kogito-runtimes/master/archetypes/kogito-quarkus-archetype/src/main/resources/archetype-resources/src/main/resources/test-process.bpmn2#/editor/bpmn2

We will use this process definition as the base of our application.

Running the Application

We will now run the Kogito application in development mode. This allows us to keep the application running while implementing our application logic. Kogito and Quarkus will hot reload the application when it is acccessed and changes have been detected.

cd /root/projects/kogito/service-task-cdi

mvn clean compile quarkus:dev

When the application has started, you can access the Swagger UI.

You should see the following page:

New Kogito Quarkus Web Page

It's working!


You've seen how to create the skeleton of basic Kogito app, and open the base process definition in the Kogito Online Tooling. Finally, you've started the application in Quarkus dev-mode.

In the next step we'll add a CDI bean that implements our text processing logic.