Camunda Modeling (BPM) with Erlang Programming

Chanaka Fernando
15 min readOct 21, 2020
Camunda BPM with Erlang programming language

In this article I’m going to describe an application which is created with Camunda BPM engine and erlang programming language. The use case of this article is more related to the domain called subscription management and this use case is to validate subscription request for the specific service code from the subscriber MSISDN. Do not bother if you are not much familiar with this Telecommunication domain specific application. The main objective of this article is to describe a method that Camunda BMP engine can work along with erlang programming language.

Component diagram for the use case scenario is depicted below.

Fg1.1 Use case components

As depicted in above diagram JMeter has been used as the API client while the Talend ESB runtime has been used as the database access layer while the database application used is PostgreSQL. All the relevant tables are created in a PostgreSQL database and access layer is exposed as an RESTful/HTTP API via Talend ESB runtime.

NOTE: Creating of database access layer with Talend ESB is described in my previous article Database(PostgreSQL) browser with Talend ESB

Camunda runtime with BPM process is deployed as a Spring application which is initialized using the web utility start.camunda.com.

Components which are used in BMP Flow created using Camunda BMP Modeler is described below.

Service Task

Fg2.1.1 Service Task

Service Tasks are used to invoke services. Service Tasks of all the flows in this use case scenarios are declared external to decouples the implementation of tasks from the process engine. Then process engine offers a work item to external workers that independently poll the engine for work to do and complete asynchronously. The attribute Implementation is set to external and the attribute Topic specifies the external task’s topic. The return value of a service execution is assigned to an already existing or to a new process variable after the service execution completes.

Business Rule Task

Fg2.1.2 Business Rule Task

A Business Rule Task is used to synchronously execute one or more rules. Business tasks of all the flows are declared DMN engine integration to evaluate a DMN decision.

The attribute Implementation is set to DMN and the attribute Decision Ref specifies the decision key i.e. the id of the DMN table to evaluate. The output of the decision i.e. decision result, is not saved as process variable automatically. It has to pass into a process variable by using a mapping of the decision result by Map decision result attribute which references the mapper to use. The result of the mapping is saved in the variable which is specified by the Result variable attribute.

Exclusive Gateway

Fg2.1.3 Exclusive Gateway

An exclusive gateway is used to model a decision in the process. When the execution arrives at this gateway, all outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to ‘true’ is selected for continuing the process.

Blank Start Event

Fg2.1.4 Blank Start Event

Blank start event define where a process or sub process starts. Blank start event is used when the process instance is started through the API.

Blank End Event

Fg2.1.5 Blank End Event

Blank end event ends current path of execution.

Message Start Event

Fg2.1.6 Message Start Event

A message start event can be used to start a process instance using a named message including name and a payload.

Message End Event

Fg2.1.7 Message End Event

When process execution arrives at a Message End Event, the current path of execution is ended and a message is sent. All Message End Events in this use case scenarios are implemented by specifying a class that implements a Java Delegate by providing the fully qualified class name in the class attribute.

Call Activity Sub process

Fg2.1.8 Call Activity

Call activity references a process that is external to the process definition by creating of a new sub process instance. The main process instance waits until the sub process is completely ended, and continues the original process afterwards. A call activity is a regular activity that requires a calledElement which references a process definition by its key i.e. the id of the process is used in the calledElement. Process variables can be passed to the sub process and vice versa. In this use case all the call activities are configured so that all process variables are passed to the sub process and vice versa. The process variables have the same name in the main process as in the sub process.

Fg2.2 BPMN Service List validation main process

A.1 — Blank Start event — The starting point of the process instance.

B.1 — Service Task — External worker fetch and lock the work items on topic service-details with process variable service_code, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. service_type, managed, service_code, partner_id, name, global_service_whitelist, global_service_blacklist, enable_service_whitelist, enable_service_blacklist, enable_global_subscription_blacklist, enable_global_charging_blacklist) which are saved as process variables automatically.

C.1 — Business Rule Task —

Fg2.2.1 DMN service-validation

Two process variables has been taken as inputs and one output variable has been created. As single variable is the output, mapping of the decision result is done by singleEntry Map decision and result of the mapping is saved in the variable which is specified by the Result variable attribute i.e. service_valid which is a new process variable.

D.1 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not service_valid}

TRUE : #{service_valid}

B.2 — Service Task — External worker fetch and lock the work items on topic partner-dnd with process variable partner_id, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. partner_dnd) which are saved as process variables automatically.

D.2 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not partner_dnd}

TRUE : #{partner_dnd}

B.3 — Service Task — External worker fetch and lock the work items on topic device-blacklist with process variables service_id and device_model_code, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. device_blacklist) which are saved as process variables automatically.

D.3 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not device_blacklist}

TRUE : #{device_blacklist}

C.2 — Business Rule Task —

Fg2.2.2 DMN list-for-all

Two process variables has been taken as inputs and one output variable has been created. As single variable is the output, mapping of the decision result is done by singleEntry Map decision and result of the mapping is saved in the variable which is specified by the Result variable attribute i.e. listed which is a new process variable.

D.4 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{listed == ‘none’}

TRUE : #{listed== ‘whitelist all’ or listed == ‘blacklist all’}

D.5 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not enable_service_whitelist}

TRUE : #{enable_service_whitelist}

E.1 — Call Activity — The main process instance waits until the sub process that is referenced by call activity is completely ended, and continues the original process afterwards. CalledElement type is defined as BPMN and its value which references a process definition by its key is configured as service-whitelist. And also Business key pass configuration to the sub process is enabled. In variables section both In Mapping and Out Mapping is set to all to pass all main process variables to the sub process and vice versa.

Sub process is as below.

Fg2.2.3 BPMN Service whitelist

E.1-EA.1 — Blank Start Event — The starting point of the process instance.

E.1-EB.1 — Service Task — External worker fetch and lock the work items on topic service-whitelist with process variables service_id and msisdn, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. listed) which are saved as process variables automatically.

E.1-ED.1 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{listed == ‘none’}

TRUE : #{listed == ‘service whitelist’}

E.1-EB.2 — Service Task — External worker fetch and lock the work items on topic service-group-whitelist with process variables service_id and msisdn, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. listed) which are saved as process variables automatically.

E.1-EG.1 — Blank End Event — Ends current path of execution.

E.1-EG.2 — Blank End Event — Ends current path of execution.

D.6 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{listed == ‘none’}

TRUE : #{listed == ‘service whitelist’}

D.7 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not enable_service_blacklist}

TRUE : #{enable_service_blacklist}

E.2 — Call Activity — The main process instance waits until the sub process that is referenced by call activity is completely ended, and continues the original process afterwards. CalledElement type is defined as BPMN and its value which references a process definition by its key is configured as service-blacklist. And also Business key pass configuration to the sub process is enabled. In variables section both In Mapping and Out Mapping is set to all to pass all main process variables to the sub process and vice versa.

Sub process is as below.

Fg2.2.4 BPMN Service blacklist

E.2-EA.1 — Blank Start Event — The starting point of the process instance.

E.2-EB.1 — Service Task — External worker fetch and lock the work items on topic service-blacklist with process variables service_id and msisdn, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. listed) which are saved as process variables automatically.

E.2-ED.1 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{listed == ‘none’}

TRUE : #{listed == ‘service blacklist’}

E.2-EB.2 — Service Task — External worker fetch and lock the work items on topic service-group-blacklist with process variables service_id and msisdn, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. listed) which are saved as process variables automatically.

E.2-EG.1 — Blank End Event — Ends current path of execution.

E.2-EG.2 — Blank End Event — Ends current path of execution.

D.8 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{listed == ‘none’}

TRUE : #{listed == ‘service blacklist’}

C.3 — Business Rule Task —

Fg 2.2.5 DMN global-blacklist-eligible

Three process variables has been taken as inputs and two output variables have been created. As multiples variables are the output, mapping of the decision result is done by singleResult Map decision and result of the mapping is saved in the variable which is specified by the Result variable attribute i.e. Lookup which is a new process variable. As Lookup is a Map variable, the actual output variables needs to be extracted and saved as process variables. Therefore output parameter to be added in input/output section of the component as below.

Name : global_subscription_blacklist_lookup
Type : Text
Value : ${Lookup.get(‘global_subscription_blacklist_lookup’)}

Name : global_charging_blacklist_lookup
Type: Text
Value: ${Lookup.get(‘global_charging_blacklist_lookup’)}

global_subscription_blacklist_lookup and global_charging_blacklist_lookup are set as new process variables.

D.9 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not global_subscription_blacklist_lookup and not global_charging_blacklist_lookup}

TRUE : #{global_subscription_blacklist_lookup or global_charging_blacklist_lookup}

E.3 — Call Activity — The main process instance waits until the sub process that is referenced by call activity is completely ended, and continues the original process afterwards. CalledElement type is defined as BPMN and its value which references a process definition by its key is configured as globalblacklist. And also Business key pass configuration to the sub process is enabled. In variables section both In Mapping and Out Mapping is set to all to pass all main process variables to the sub process and vice versa.

Sub process is as below.

Fg2.2.6 BPMN global blacklist

E.3-EA.1 — Blank Start Event — The starting point of the process instance.

E.3-ED.1 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not global_subscription_blacklist_lookup}

TRUE : #{global_subscription_blacklist_lookup}

E.3-EB.1 — Service Task — External worker fetch and lock the work items on topic global-subscription-blacklist with process variable msisdn, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. listed) which are saved as process variables automatically.

E.3-ED.2 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{listed == ‘none’}

TRUE : #{listed == ‘global subscription blacklist’}

E.3-ED.3 — Exclusive Gateway — All outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to true is selected for continuing the process. One sequence flow is named as TRUE while other is named as FALSE. Condition type of two sequence flows are configured as Expression and expressions are as below.

FALSE : #{not global_charging_blacklist_lookup}

TRUE : #{global_charging_blacklist_lookup}

E.3-EB.2 — Service Task — External worker fetch and lock the work items on topic global-charging-blacklist with process variable msisdn, then do the necessary processing and database lookups and finally complete the work item with output variables (i.e. listed) which are saved as process variables automatically.

E.3-EG.1 — Blank End Event — Ends current path of execution.

E.3-EG.2 — Blank End Event — Ends current path of execution.

E.3-EG.3 — Blank End Event — Ends current path of execution.

F.x — Message End Event — The current path of execution is ended and a message is sent which is implemented by specifying a class that implements a Java Delegate. Message Name to be sent is configured as ListStatus and process variables (i.e. service_valid, partner_dnd, device_blacklist, listed) and businessKey are correlated with Message ListStatus with in Java Delegate.

The message received by below sub process and the message start event in this sub process is used to start a process instance using a named message ListStatus. The sub process is as below

Fg2.2.7 BPMN Send list status

F.x-FH.1 — Start a process instance using a named message including name and a payload.

F.x-FC.1 — Business Rule Task —

Fg2.2.8 DMN list-status

Two process variables has been taken as inputs and one output variable has been created. As single variable is the output, mapping of the decision result is done by singleEntry Map decision and result of the mapping is saved in the variable which is specified by the Result variable attribute i.e. status which is a new process variable.

F.x-FB.1 — Service Task — External worker fetch and lock the work items on topic send-response with process variable status, then do the necessary processing and finally complete the work item with no output variables.

F.x-FG.1 — Blank End Event — Ends current path of execution.

Fg 3.1 Use case interaction flow

Considering the erlang application, there are four main components.

  1. Camunda API client — API client component which is used to access Camunda RESTful API.
  2. Talend API client — API client component which is used to access database access layer exposed through Talend ESB runtime.
  3. API server — Expose an API which is used to access the system functionality for the API client. This component use Camunda API client to access relevant resource end-points to start main process instance. At the starting of a new process instance a new business key is generated by API server and pass as the businessKey parameter which is used as a kind of transaction key for the entire flow. Additionally the parameters i.e. service_code and msisdn are passed as variables. Mapping of businessKey to process id of the requestor is cached.
  4. External executor — Camunda API client is used to fetch and lock work items in Camunda Service Tasks. Variables retrieved are used to lookup database tables by using Talend API client and complete the work items by using Camunda API client. Final states of the Flows which are fetched as work items from send-response Service Task topic are send to the waiting process which has sent the original request (process ids of the original requestor is mapped by businessKeys received with work items).

Resources :

GitHub location for the public repository of the above use case is mentioned below.

https://github.com/camunda-erlang

--

--