Process Events Add-On: Current State and Practical Insights

Creating solutions that can emit and react to events in real-time is a practice that gets more and more natural as event-driven solutions’ popularity grows. Combining of events and business processes is a way to unlock powerful capabilities in automation solutions.

In this article, we’ll explore how to leverage such capabilities using Kogito-powered automation, Quarkus, and Kafka.

Why Combine Events and Processes?

Integrating events and processes opens doors to interesting use cases and expansion of business process automation solutions:

Process Monitoring: By emitting events at various stages of a process, you can create real-time dashboards and monitor process execution as it happens.

Auditability: Maintaining a complete audit trail for compliance is made easier through detailed event logs that record every significant process change.

Event-based Integration: Trigger actions based on events in a decoupled fashion, delivering loosely coupled, scalable microservices.

Facilitate Analysis: Enable external consumption of the changes in a process, through the events. With that, spot bottlenecks and find ways to optimize processes.

We will explore the events add-on through a mix of concepts explanations and practical execution insights.

The use case is based on a basic process for approval of credit card applications:


Project configurations

The Events and Processes Add-On (org.kie:kie-addons-quarkus-events-process) is an optional component that can expand the capabilities of a process service. With it, services can emit events associated with state transitions in process elements. Architects can design solutions that consume such events to enable real-time monitoring, auditing, and integration with external microservices.

To enable automatically publishing of events in Quarkus-based process service we need the to set the right dependencies and Kafka configurations:

pom.xml:

<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-addons-quarkus-events-process</artifactId>
<version>9.1.0-ibm-0001</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-kafka
</artifactId>
</dependency>

application.properties:

# Kafka broker URL
kafka.bootstrap.servers=localhost:9092

# Process Instance Events
mp.messaging.outgoing.kogito-processinstances-events.connector=smallrye-kafka
mp.messaging.outgoing.kogito-processinstances-events.topic=kogito-processinstances-events
mp.messaging.outgoing.kogito-processinstances-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

# User Task Events
mp.messaging.outgoing.kogito-usertaskinstances-events.connector=smallrye-kafka
mp.messaging.outgoing.kogito-usertaskinstances-events.topic=kogito-usertaskinstances-events
mp.messaging.outgoing.kogito-usertaskinstances-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

Optionally, it’s possible disable specific event channels. To do so, use the following properties:

kogito.events.usertasks.enabled=false
kogito.events.variables.enabled=false

Practical Exploration: Process Events Add-on

The Business Process

Let’s take a closer look at the BPMN implementation of the credit card application approval process.

The two main paths of the flow, mainly determined by automated decisions (Credit Card Eligibility, DMN), are:

  • Automatic: End-to-end execution, no need of human intervention.
  • Expert review required: New task is assigned to a particular user, or group of users. The task goes through different stages, until its completion. The outcome defines the further processing and flow completion.

The multiple state changes throughout the process execution can be tracked using the events automatically and transparently published by the add-on. It’s a clean approach for reacting and taking action based on changes in state of processes, user tasks, and process variables.

About the Topics

These are the main topics holding events of state changes in a process service:

kogito-processdefinitions-events For events related to process definitions, including metadata and node structures. Capturing and tracking the definition and version of processes.
kogito-processinstances-eventsFor events related to the lifecycle of process instances.
Includes events for node activations, state changes, and variable updates.
kogito-usertaskinstances-eventsFor events related to user tasks within process instances.
Includes task state changes and variable updates resulting from user tasks interaction.

Next, let’s learn more details about each of these topics and the events data.

About the Events

Standards simplify the usage and consumption of events. The events published by the add-on are structured following the CloudEvents specification.

Here’s a summary of the common fields across the different types of events of the add-on:

specversion Version of CloudEvents specification
idUnique event’s identifier.
sourceWhere the event comes from.
typeThe type of event.
timeWhen the event occurred.
dataThe details of that event. This will change for the different types of event and associated info.

Now let’s cover the details of the main types of events that happens throughout a process execution: process instance events, user tasks events and variable events.

Process Instance Events

New events are published when a process instance is created, updated, or completed. These events’ data can be used for generating insights about the lifecycle and overall process instances execution.

Here’s an example with the event’s data published when a new process instance is started for the process with ID “credit-card-application“:

{
"id": "df900d05-0641-4063-9e37-3e3648465e44",
"source": "http://localhost:8080/ccapplicationapproval",
"type": "ProcessInstanceStateDataEvent",
"time": "2024-07-17T17:25:21.93199-03:00",
"data": {
"eventDate": "2024-07-17T17:25:21.931-03:00",
"eventUser": null,
"eventType": 1,
"processId": "ccapplicationapproval",
"processVersion": "1.0",
"processType": "BPMN",
"processInstanceId": "b2b79a3e-ba43-49a5-9c10-fe81bb50c04a",
"businessKey": null,
"processName": "ccapplicationapproval",
"parentInstanceId": null,
"rootProcessId": null,
"rootProcessInstanceId": null,
"state": 1,
"roles": null,
"slaDueDate": null
}
}

The fields which are null in the example above, are optional configurations not used in the example process used.

User Task Events

User task events are published for the following human task operations: create, update, complete, and assign. You can use these events to track user task progress, performance, and cycles. The example below shows an event published when the user “jdoe” completes the task “reviewApplication” in the process instance with ID “b2b79a3e-ba43-49a5-9c10-fe81bb50c04a”:

Process Variable Events

Events are published for process variable creation, updates, or deletes. Keep track of data changes and integrate with external solutions for enabling detailed audit logs.

The following event data is published when the “approval” variable is assigned the value “Approved,” in the process instance with ID “b2b79a3e-ba43-49a5-9c10-fe81bb50c04a”:

{
"data": {
"eventDate": "2024-07-17T17:28:42.746-03:00",
"eventUser": null,
"processId": "ccapplicationapproval",
"processVersion": "1.0",
"processInstanceId": "b2b79a3e-ba43-49a5-9c10-fe81bb50c04a",
"nodeContainerDefinitionId": null,
"nodeContainerInstanceId": null,
"variableId": "approval",
"variableName": "approval",
"variableValue": "Approved"
},
"kogitoprocinstanceid": "b2b79a3e-ba43-49a5-9c10-fe81bb50c04a",
"kogitoprocid": "ccapplicationapproval",
"kogitoaddons": "source-files,process-management,process-svg",
"kogitoprocversion": "1.0",
"kogitoprocist": "1",
"kogitoproctype": "BPMN",
"kogitovariablename": "approval"
}
Process Definition Event

When the application starts, events are published for the existing process definitions. For example:

{
"id": "df9d0498-e5ca-4cef-b1ec-5c795cb2efa9",
"source": "http://localhost:8080/ccapplicationapproval",
"type": "ProcessDefinitionEvent",
"time": "2024-07-17T17:22:40.107127-03:00",
"data": {
"id": "ccapplicationapproval",
"name": "ccapplicationapproval",
"version": "1.0",
"type": "BPMN",
"addons": ["source-files", "process-management", "process-svg"],
"endpoint": "http://localhost:8080/ccapplicationapproval",
"metadata": {
"TargetNamespace": "http://www.omg.org/bpmn20"
},
"nodes": [/* node details omitted for brevity */]
}
}

Execution results and considerations

Let’s take a closer look, at the behavior captured through events throughout the execution of the following process instance:

The execution of the process instance above, have these key stages:

  1. User applies for credit card approval, starting a new process instance;
  2. Application cannot be automatically completed, and is sent to manual review from bank analyst. At this point, a new user task is now available for execution;
  3. The user claims the task;
  4. The user completes the task by informing the evaluation outcome: “Approved”.
  5. The process moves forward, cc details are generated and the process ends.

Here’s an overall representation of the events that are published by the add-on in our service:

When tracked since the moment the process service (Quarkus application) is bootstrapped, going through the execution of the process instance up until completion, several are most of the events observed.

1. Application Start
As the application starts, a new event registers the process definitions. In this example, a ProcessDefinitionEvent brings information about the BPMN process.

#ActionEvent Type
1Process definition registeredProcessDefinitionEvent

2. New Process Instance
When a new instance is created, a series of events are published, as the nodes execute as defined, until the process reaches the next wait state (user task).

#ActionEvent Type
1Process instance createdProcessInstanceStateDataEvent
2Start nodeProcessInstanceNodeDataEvent
3Variable initializationProcessInstanceVariableDataEvent
4Script task execution (Log application received)ProcessInstanceNodeDataEvent
5Decision task execution (Credit Card Eligibility)ProcessInstanceNodeDataEvent
6Variable update (approval)ProcessInstanceVariableDataEvent
7Gateway (Split)ProcessInstanceNodeDataEvent
8User task ready (Review Application)UserTaskInstanceStateDataEvent

3. User Task Execution
One user task can result in multiple interactions and updates. In this example, the user claims and completes the task with an update to one of the process variables. The events published were:

#ActionEvent Type
9User task assignmentUserTaskInstanceAssignmentDataEvent
10User task claimUserTaskInstanceStateDataEvent
11User task variable updateUserTaskInstanceVariableDataEvent
12User task completionUserTaskInstanceStateDataEvent
13Process variable update (approval)ProcessInstanceVariableDataEvent

4. Process Continues After User Task
The process moves forward after the user task is completed, and the tasks are executed until it reaches the end event.

#ActionEvent Type
14Gateway (Split)ProcessInstanceNodeDataEvent
15Service task execution (Generate CC Details)ProcessInstanceNodeDataEvent
16Variable update from service (creditCard)ProcessInstanceVariableDataEvent
17End node (Approved)ProcessInstanceNodeDataEvent
18Process instance completionProcessInstanceStateDataEvent

You can find code examples of all events data mentioned in this section, on the sample projects file: events-examples.md.

Final thoughts

When designing solutions with event-driven capabilities such as the one we explored, remember to evaluate and define how the organization should handle the new characteristics of the solution, for example:

Security and Privacy
When transmitting sensitive data, explore the recommended ways to securing data and integration with your events platform.

High events volume
Be prepared to handle high volumes of events, especially for frequently executed processes. Work on assuring proper scaling and event buffering mechanisms in the Kafka environment.

Event Retention Policy
Storing events for long periods of time requires more storage resources, which can directly impacts the final cost. Adjusting event retention policies can give you a better control of storage costs.

Enabling events for kogito-powered process services using the process events add-on, is a powerful way to increase transparency in our process automation solutions.

Additional Resources


Discover more from Karina Varela

Subscribe now to keep reading and get access to the full archive.

Continue reading