The example demonstrate how to create a task listener for a BPMN process and register it on the event bus.
- Checkout the project with Git
- Read and run the unit test
Add the plugin as dependency in pom.xml:
...
<dependencies>
...
<dependency>
<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-reactor-core</artifactId>
</dependency>
...
</dependencies>
...
And add it as process engine plugin in the process engine configuration:
ProcessEngineConfiguration configuration = new StandaloneInMemProcessEngineConfiguration() {
{
// register the plugin
this.getProcessEnginePlugins().add(CamundaReactor.plugin());
}
};
Now, create a task lister that should set the due date of a task and add a candidate group.
@CamundaSelector(type = "userTask", event = TaskListener.EVENTNAME_CREATE)
public class TaskCreateListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
delegateTask.setDueDate(Process.DUE_DATE);
delegateTask.addCandidateGroup(Process.GROUP_1);
}
}
The annotation @CamundaSelector
specifies that the listener should be invoked when the process engine enters a user task (type='userTask') and creates a task entity (event='create').
At least, the listener must be registered on the event bus. For example, by self-registration in constructor:
public TaskCreateListener() {
CamundaReactor.eventBus().register(this);
}