Camunda Workflow Engine

Moneim Ketata
Blue Harvest Tech Blog
7 min readNov 16, 2022

--

Introduction

Business process management is one of the best ways to improve and processes in an organization.

It can eliminate human error and process gaps while improving efficiency and compliance.

So I am assuming that everyone is wondering what is Business process management ?

What is Business process management ?

Business process management (BPM) is the practice of modeling, analyzing, and optimizing end-to-end business processes to help meet your strategic business goals, such as the improvement of your customer experience framework.

BPM methodology can be applied to tasks and processes that are often repeated, ongoing, or predictable.

What is process (workflow)?

In essence, a process (or workflow) simply refers to a series of tasks that need to be performed to achieve a desired result.

What is workflow engine?

A workflow engine is a software application that helps organizations initiate and automate tasks. It manages and monitors activities in a workflow and determines which task to transition to based on predefined processes.

It’s typically a key component of business process management software and helps organizations streamline processes by allocating tasks and communicating data to both employees and management.

What are the benefits of using a workflow engine ?

  • Explicit processes: Processes become explicit instead of being “buried” somewhere in your code and can therefore be changed much more easily and dynamically without relaunching your application.
  • State management: The workflow engine is responsible for the persistence of each instance.
  • Status transparency: the status of each instance can be checked at any time by simply requesting the workflow engine. Monitoring can be done directly on the graphic diagram.
  • Visibility: Graphical workflows can be used to discuss the process between business people and developers, as well as between developers and Ops.

How to draw a workflow ?

Business Process Model and Notation (BPMN) is the global standard for process modeling.

Let’s explore some basic components from BPMN :

Every process needs a starting point, which is a start event in BPMN. This is where the process flow will begin whenever a new process instance is started. End events are where a flow will end.

Tasks :

  • Service task is always related to software functionality needs to be executed , most of the time we call service , microservice , a method , a function or whatever.
  • User task is used to model a task which has to be executed by a human performer. This task is marked with a small user icon in the upper left corner.
  • Script task is an automated activity which executes the script entered in the main script section. This task is marked with a small white script icon in the upper left corner.

Gateways

  • Exclusive Gateway allows you to make a decision based on data.
  • Inclusive Gateway allows for making multiple decisions based on data.
  • Parallel Gateway allows you to split the flow into concurrent paths.
  • Event based Gateway allows you to make a decision based on events.

Events

Events in BPMN can be thrown, or caught, respectively referred to as throw or catch events

  • Message are events which reference a message; they are used to wait until a proper message is received.
  • Timer events are events triggered by a defined timer.

What is Camunda 7 ?

Camunda is Java based framework supporting BPMN for workflow and process automation, it can be used as embedded in any java application or standalone, it’s light and easy to integrate.

Why choose Camunda ?

  • Open source
  • modern java support
  • Customizable
  • Compatible with Spring
  • REST API
  • Easy to integrate with microservices architecture

Camunda 7 overview

  • REST API The REST API allows you to use the process engine from a remote application.
  • Camunda Tasklist A web application for human workflow management and user tasks that allows process participants to inspect their workflow tasks and navigate to task forms in order to work on the tasks and provide data input.
  • Camunda Cockpit A web application for process monitoring and operations that allows you to search for process instances, inspect their state and repair broken instances.
  • Camunda Admin A web application that allows you to manage users, groups and authorizations.

What we are trying to achieve in Blue Harvest ?

Since the IT market is one of the most competitive markets, so changing our recruitment process and automate it is one of the most important tasks we need to do as an IT company to make sure we make our elite engineers life more easier.

Our recruitment process is decomposed in 3 important steps :

  • Know your candidate
  • Technical assignment
  • Offer discussion

In this article our main focus will the second part Technical assignment let’s have look to our BPMN diagram for the Technical assignment

The first step in our process is to send an email to the candidate containing all the details of the assignment and how he can confirm that he finished the assignment. To implement this step we are relying to an open source connector that helps us to send an email easily with just some configuration

# send mails via SMTP
mail.transport.protocol=smtp

mail.smtp.host=smtp.gmail.com
mail.smtp.port=465
mail.smtp.auth=true
mail.smtp.ssl.enable=true
mail.smtp.socketFactory.port=465
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

# poll mails via IMAPS
mail.store.protocol=imaps

mail.imaps.host=imap.gmail.com
mail.imaps.port=993
mail.imaps.timeout=10000

# if peek = false then the polled mails are marked as read
mail.imaps.peek=false

# additional config
mail.poll.folder=INBOX
mail.sender=test@test.com
mail.sender.alias=User Inc

mail.attachment.download=true
mail.attachment.path=attachments

# credentials
mail.user=test@test.test
mail.password=testPassword

The second step in our process is to wait for the candidate to finish his assignment or after 7 days we need to notify him. To achieve this part we need to use a message event that once we received an email from the candidate in which he indicate that he finished his assignment we correlate a message into the process to make sure we can go to the next step.

To make sure everything works fine, we need an extra hand from java code, we need to implement an ExecutionListener which will execute some side effect treatment. So we gonna tell our workflow engine once you reach the eventGateway try to execute our code before


import com.blueharvest.mmf.utils.constants.WorkflowVariables;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.ExecutionListener;
import org.camunda.bpm.extension.mail.notification.MailNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ReceiveAssignementListener implements ExecutionListener {

@Autowired
private MailNotificationService mailNotificationService;

@Autowired
private RuntimeService runtimeService;

@Override
public void notify(DelegateExecution delegateExecution) throws Exception {
mailNotificationService.registerMailHandler(mail -> {
String fromEmail = mail.getFrom().substring(mail.getFrom().indexOf('<') + 1, mail.getFrom().indexOf('>'));
if ((fromEmail.equals(delegateExecution.getVariable(WorkflowVariables.CANDIDATE_EMAIL))) &&
mail.getSubject().equals(WorkflowVariables.ASSIGNMENT_RECEIVED_SUBJECT)) {
runtimeService.createMessageCorrelation("Assignement-Received")
.processInstanceId(delegateExecution.getProcessInstanceId())
.correlate();
}
});
mailNotificationService.start();
}
}

Let’s assume that the candidate already finished his assignment and now we need to fetch potential reviewers depends on the technical stack of the assignment.

We need a service task to implement this part you can find an example of an implementation down below


import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

@Component
public class CheckAvailableReviewersDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
// TODO business code needs to be implemented
delegateExecution.setVariable("reviewerFound",Boolean.TRUE);
}
}

to call this code we need to add a Delegate expression ${checkAvailableReviewersDelegate} this part make sure to call our spring bean to be executed when reaching this step:

Now we reach a User Task for the Code Review , the reviewer should give his feedback and if everything is okay we need him to provide some time slots to plan the technical interview.

In this task we would like to use an HTML forms instead of the forms generated by camunda, to do so we need just to call our forms simply while modeling our process.

Next we need to send the slots available and it’s up to the candidate to accept or not but this part could be part of change since there is some better tools to use.

The last part is the Technical interview the interviewer will give his final feedback , for this part we trying to use the full potential of camunda , that’s why we are using camunda forms

In our POC we used camunda as embedded and it’s really easy to configure just go to this url https://start.camunda.com/ , then choose what you need and generate your project.

Conclusion

In summary, what we trying to achieve is to automate our process that takes too much time to be finished manually, but camunda doesn’t have only a purpose to automate human process but also it can orchestrate communication between microservices in a microservices architecture.

how to achieve that ? stay tuned to our next article ;)

--

--