How to create Activiti Message Event with Spring Boot Example

In this tutorial, we’re gonna look at Activiti Message Event Example with Spring Boot.

Related Articles:
Introduction to Activiti – a Java BPM Engine
Activiti Message Event with Spring Boot Example

I. Activiti Message Event Overview

A Message Event is a named message that always directs towards a single receiver.

To define Message Event, we use messageEventDefinition element. For example:

Activiti Engine is not concerned with receiving messages. We have to implement our own infrastructure to deal with received messages. Then we can decide what to do with them.

In the example, we use message to trigger the start of a Process Instance. These are some methods (from Runtime Service):

II. Practice

1. Technology

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.4.RELEASE
– Spring Boot: 1.5.3.RELEASE

2. Project Overview

We can start Process by one of two messages: messageOne and messageTwo. Before end Event, a Notification will throw a message in System Console.


– Process definition will be written under XML format in process/process.bpmn20.xml file.
MyService provides service methods for Controller such as: startProcess(), getTasks(), completeTask(). Those functions can be done with help of some @Autowired objects which are instances of these classes:
+ RuntimeService
+ TaskService
MyController is a REST Controller which has request mapping methods for RESTful requests such as: /startprocess, /tasks, /completetask.
pom.xml contains dependencies for:
+ Activiti Spring Boot Starter Basic
+ Spring Boot Starter Web
+ H2 database: Activiti Engine needs a database to store its data. By default, it will connect to an in-memory H2 database.
+ Groovy: scripting engine for running Script Task in process.

Notes: We must add Groovy Jar file (groovy-all-2.4.10.jar) to make it work.
3. Step by step
3.1 Create Spring Boot project

Using Spring Tool Suite/Eclipse to create Project and add Dependencies to pom.xml file:

– Add Groovy Jar file (groovy-all-2.4.10.jar) as Referenced Library.
(Groovy: scripting engine for running Script Task in process)

3.2 Define Process

Under src/main/resources, create processes folder and add process.bpmn20.xml file:

3.3 Create Service Class

3.4 Create Controller Class

3.5 Run & Check Result

– Config maven build:
clean install
– Run project with mode Spring Boot App
– Check results by open your browser and send request:

Request 1: Start Process by MessageOne and assign tasks to John

Request 2: show tasks of John

Request 3: complete Task

And System Console shows:

Request 4: Start Process by MessageTwo and assign tasks to John

And System Console shows:

III. Source Code


By grokonez | May 17, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *