Camunda SpringBoot Starter -4

Güvenç Kazancı
turkcell
Published in
3 min readSep 14, 2021

Introduction

This is the fourth article of this series. You can find links below to read first three of it.

In this fourth article, I will tell about;

  • history event handler

History Event Handler

Camunda already stores audit data regarding the flows in its predefined database tables. There is a history level parameter that you can configure in application.properties file.

camunda.bpm.history-level=ACTIVITY

Camunda documentation gives details about the available history levels.

What we are interested in here is to use our own history handler, because we might want to design our own history tables or store data in our own audit tool.

Camunda makes this possible by providing a history event handler interface and configuring it in the process engine.

Let’s start coding !

Model and Repository

We will add a simple entity to keep track of all the steps passed by when a flow starts to run. We will use h2 in memory database to test it.

Service

And we would need a service to save records into database.

History Handler

Our database design and service layer is completed. Now we need to use them to save the flow steps.

As always, camunda provides us an interface to use and customize the history event handler which is HistoryEventHandler.java :)

HistoryEvents can have different instances of classes. Because we configured our history level to ACTIVITY, we will only get activity events. I find this quite enough for my use cases. If you need more than that, you can try changing the history level. Please see this link for the available history levels.

What we achieve here is to catch the events for Script Task, User Task, Service Task and Process Create.

Sadly, history event handler does not catch transition events, but I have another solution for that. I add SequenceFlowExecutionListener to all my sequences in bpmn parse listener and save the transition steps into my history table. For more details about this, please see my previous post Camunda SpringBoot Starter -3

Now we need to configure the process engine and set the CustomHistoryEventHandler so that camunda will know about it.

We are ready to go. Let’s run this sample flow and check everything works ok.

After running the curl command, I expect to see my table populated with audit data. Let’s go to h2 console and see it.

http://localhost:8080/h2-console/

As expected, whole process can be tracked by step name and step type.

Sum Up

Here is the github link where you can find the project covering all the content mentioned in this post.

--

--