jhon
August 1, 2018, 7:42am
1
Hi all,
I had embedded a camunda process engine server in my application that interfaces camunda through the REST API. Camunda server runs many process definitions dinamically deployed. Is it possibile to configure into camunda server a global event listener so I can run some custom logic when something happens on tasks ( e.g. a task is created or suspended and so on ).
Thanks
@Ingo_Richtsmeier If I were to listen on all task and process level events what would be the best implementation.
I did see some reference to GitHub - camunda/camunda-bpm-reactor: Event Driven process applications framework. But not able to get bpm-reactor working with tomcat based configuration
@harish_malavade Are your process applications are Spring based applications?
If yes, you can try camunda-spring-event-bridge like below:
@Slf4j
@Component
public class CamundaEventListeners {
@EventListener
public void onTaskEvent(DelegateTask taskDelegate) {
log.info("Handling mutable DelegateTask:{}", taskDelegate.getTaskDefinitionKey());
}
@EventListener
public void onTaskEvent(TaskEvent taskEvent) {
log.info("Handling immutable TaskEvent:{}", taskEvent.getTaskDefinitionKey());
}
@EventListener
public void onExecutionEvent(DelegateExecution executionDelegate) {
log.info("Handling mutable DelegateExecution:{}", executionDelegate.getCurrentActivityName());
}
@EventListener
public void onExecutionEvent(ExecutionEvent executionEvent) {
log.info("Handling immutable ExecutionEvent:{}", executionEvent.getProcessDefinitionId());
}
@EventListener
public void onHistoryEvent(HistoryEvent historyEvent) {
log.info("Handling mutable HistoryEvent:{}", historyEvent.getEventType());
}
}
The process engine can be hooked-up to the Spring event bus. We call this the “Spring Eventing Bridge”.
camunda.bpm.eventing.execution=true
camunda.bpm.eventing.history=true
camunda.bpm.eventing.task=true
By default, the Spring eventing is enabled by a engine plugin.
Hello @harish_malavade ,
I will stick to my answer from this post: Global event listener on Process Engine Server - #2 by Ingo_Richtsmeier .
Next to the example is another one called bpmn-parse-listener
. Have a look at the parse listener implementation and add your listener to all events where you need it.
Hope this helps, Ingo
Thank you for the response, our application are not spring enabled yet, we are deploying to camunda tomcat in AWS Ec2. are there these configuration settings in tomcat based camunda for bpm-platform.xml?
Thank you @Ingo_Richtsmeier . Does this mean I need to add parsers per event and implement the listeners on each event if I were to capture all task level events ?
Something like below
Then my UserTaskCreateParser would look like
@Override
public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
ActivityBehavior activityBehavior = activity.getActivityBehavior();
if(activityBehavior instanceof UserTaskActivityBehavior ){
UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) activityBehavior;
userTaskActivityBehavior
.getTaskDefinition()
.addTaskListener(TaskListener.EVENTNAME_CREATE, new CreateTaskListener());
}
}
UserTaskAssignParser
@Override
public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
ActivityBehavior activityBehavior = activity.getActivityBehavior();
if(activityBehavior instanceof UserTaskActivityBehavior ){
UserTaskActivityBehavior userTaskActivityBehavior = (UserTaskActivityBehavior) activityBehavior;
userTaskActivityBehavior
.getTaskDefinition()
.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, new OlympusTaskListener());
}
}
And then add these parser to plugin
List preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners();
if(preParseListeners == null) {
preParseListeners = new ArrayList();
processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
}
preParseListeners.add(new UserTaskCreateParser());
preParseListeners.add(new AssignTaskParser());