As already mentioned in the second part of this series, building systems of this type consists of several components. In this part we describe the integration of a BPMN 2.0 capable workflow management system and a business rule engine in our IoT prototype.

Why do we need such things

Currently we live in times of a knowledge society and fast changing business requirements. Business flexibility is needed more than ever and also requires flexible business processes in companies. This could be realized through the cooperation of IT and business to develop automated BPMN 2.0 models.

But this is not appropriate in an environment with many complex business rules which are changing multiple times in a short period. In such cases, business departments cannot wait at the next planned release of an application. So this scenario is predestined for the use of a business rule engine. It allows to externalize business rules from an application and develop and manage it in an unified way.

Thus, a process engine in combination with a business rule engine makes it possible to have modifiable automated processes and application-independent development of business rules.

Many companies have already recognized the need of a process engine and a business rule engine. Accordingly we focused to improve our experience in integration of already existing technologies in many companies with IoT. From the perspective of a company, it could be a key factor to keep already made investments in IT save and integrate it with IoT for new market potential.

Based on our focus and expertise, we decide to use camunda BPM as BPMN 2.0 capable workflow management system and Drools Expert by JBoss as business rule engine.

Use of camunda BPM

We have embedded the process engine inside our Spring application. In this way we could still use our Spring expertise. The integration went well in a few easy steps which are described in short below.

After adding the necessary project dependencies to our Maven project we extend the web.xml with a DispatcherServlet and configure the embedded camunda ProcessEngine and the ProcessApplication inside it as shown below.

[code wraplines=“false“ language=“xml“ collapse=“true“]

${} ${hibernate.dialect} ${} ${hibernate.show_sql} ${hibernate.format_sql} com.opitz.iotprototype.entities


Next we have configured a deployable process archive by the descriptor file processes.xml like below.

[code wraplines=“false“ language=“xml“ collapse=“true“]

default false true


That was all for extending our application with camunda BPM. Afterwards we start with development of our BPMN 2.0 model. We have realized the use cases to react to the presence & absence of users. The main steps in both cases are

  • check if user is first/last,
  • switch Kitchen plugs on/off,
  • switch special plugs on/off (injected as business rules),
  • switch user assigned plugs on/off and
  • finally set current user state.

The BPMN 2.0 model looks finally as shown below:

PlugSwitchProcess modeled with camunda BPM
PlugSwitchProcess modeled with camunda BPM

After completing the BPMN 2.0 model, we start to enrich it with Java implementations.
Therefore we defined so-called delegates (in some cases with field injection) in DispatcherServlet and used CDI to link these delegates with our model. Following code snippet shows a few definitions.

[code wraplines=“false“ language=“xml“ collapse=“true“]


Next we link the delegates with the BPMN 2.0 model via camunda Modeler properties view. Following image illustrates this step.

camunda BPMN 2.0 Modeler properties view
camunda BPMN 2.0 Modeler properties view

And in fact if a building has no kitchen, we have modeled a boundary Error Event as a business error as shown below.

camunda boundary error event
camunda boundary error event


Use of Drools Expert

We have embedded the rule engine inside our Spring application by adding the necessary project dependencies to our Maven project, too. Afterwards we add Business Rule Tasks to the BPMN 2.0 process model for use of the rule engine as shown below.

camunda BPM Business Rule Task
camunda BPM Business Rule Task

The implementations are linked as delegates, too. First a KnowledgeBase (Production Memory) with a corresponding business rule file (*.drl) is created. We defined business rule files for both cases and add these files to our project as resources. Following code snippet shows the part for reacting to presence of the user ‚jack‘.

[code wraplines=“false“ language=“text“ collapse=“true“]

package com.opitz.iotprototype

import com.opitz.iotprototype.entities.User;
import java.util.HashSet;

rule „Switch ON special rooms for jack“
u : User( username == „jack“ )
HashSet specials = new HashSet();
specials.add( „meetingroom“ );
specials.add( „office123“ );
insert( specials );
System.out.println( „## drools: special rule to switch ON special rooms for jack ##“ );


Of course, it’s possible to store these files elsewhere outside the project. The next steps were to create a new session (Working memory) by the production memory and add the current data, so-called facts, to the working memory. This has the effect that the business rule engine applies pattern matcher on both memories and response the matched results in so-called agenda. Afterwards we filter out the resulted plug names from the session. Following image illustrates the mentioned parts of  Drools Expert.

Drools Expert overview
Drools Expert overview


Accumulated Experience

We have noticed that such heterogeneous systems need some new management tasks, e.g., device management, and even more alignment among different areas. Another point is that we embedded camunda BPM inside our Spring application and communicate with the process engine by the Java API. Alternatively it’s possible to separate camunda BPM and Drools Expert from Spring and use camunda REST-API to communicate with the process engine.

In our prototype, we have only a few business rules. So it takes some time to parse these few rules, which is not adequately. A rule engine is more efficient for complex rules with a number greater than 25.

Thus whenever a device trigger an event it’s processed by Oracle CEP and fired via REST to our Spring application. Next it’s forwarded to camunda BPM which use Drools Expert to determine special rules for given user and execute it. As you can see, integration of well-established technologies like Java, Spring and REST with the world of IoT is really possible.

Finally, the interaction among already established technologies and IoT enable new business and technical possibilities for companies and become more important soon.


If you would like to check the source code, look on GitHub for our project.

Or check out the other parts of this series:

Alle Beiträge von Halil Hancioglu

Schreibe einen Kommentar