Spring boot "onExecutionEvent" not working when using process engine config

I have a spring app where I had added event listeners on execution as below:

@Component
public class WorkflowListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowListener.class);
    @EventListener
    public void onTaskEvent(DelegateTask taskDelegate) {
        // handle mutable task event
        LOGGER.info("process=processTaskCompletion status=onTaskEvent taskDelegate={}", taskDelegate);
    }

    @EventListener
    public void onTaskEvent(TaskEvent taskEvent) {
        // handle immutable task event
        LOGGER.info("process=processTaskCompletion status=onTaskEvent taskEvent={}", taskEvent);
        // mileStoneManager.processMileStone("test13");
    }

    @EventListener
    public void onExecutionEvent(DelegateExecution executionDelegate) {
        // handle mutable execution event
        LOGGER.info("process=processTaskCompletion status=onTaskEvent executionDelegate={}", executionDelegate);

    }

    @EventListener
    public void onExecutionEvent(ExecutionEvent executionEvent) {
        // handle immutable execution event
        LOGGER.info("process=processTaskCompletion status=onTaskEvent executionEvent={}", executionEvent);

    }
}

For it to work, I set the properties in yml file as below:
camunda.bpm.eventing.execution: true
camunda.bpm.eventing.history: true
camunda.bpm.eventing.task: true

This used to work and I was able to get events as the process execution progressed in camunda.
After this, I configured Process Engine through XML file, camunda.cfg.xml as below. Since I added this config, I no longer get any events on exec of the process. If I remove this file it starts working again. What am I missing here?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="processEngineConfiguration" class="org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration" >
        <!-- activate bpmn parse listener as process engine plugin -->
        <property name="processEnginePlugins">
            <list>
                <bean class="com.example.workflow.service.parseListener.ProgressLoggingSupportParseListenerPlugin" />
            </list>
        </property>
        <property name="jobExecutorActivate" value="true" />
    </bean>
</beans>

Is there a property I need to add to the cfg.xml file? I went through the documentation: https://docs.camunda.org/manual/7.6/user-guide/process-engine/the-job-executor/ but not able to figure this out. Appreciate any help on this. Thanks.

@mns For spring applications, camunda.cfg.xml file not required. You can provide configurations in application.yml or spring java configuration.

By default, the Spring eventing is enabled by a engine plugin.

In application.yml,

camunda:
  bpm:
	eventing:
	  execution: true
	  task: true
	  history: true

On the execution event stream, DelegateExecution s (mutable) and ExecutionEvent s (immutable) can be received. The task event stream offers DelegateTask s (mutable) and TaskEvent s (immutable). On the history event stream, only HistoryEvent s (mutable) are published.

@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());
  }
}

Verify the below logs (line 2 & 3 for onExecutionEvent() ):

c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:start
c.e.w.events.CamundaEventListeners : Handling mutable DelegateExecution:Start
c.e.w.events.CamundaEventListeners : Handling immutable ExecutionEvent:ProducerProcess:3:9daed8ea-dcbe-11ea-a69c-507b9dc4ed46
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:start
c.e.w.events.CamundaEventListeners : Handling mutable DelegateExecution:Start
c.e.w.events.CamundaEventListeners : Handling immutable ExecutionEvent:ProducerProcess:3:9daed8ea-dcbe-11ea-a69c-507b9dc4ed46
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:end
c.e.w.events.CamundaEventListeners : Handling mutable DelegateExecution:Start
c.e.w.events.CamundaEventListeners : Handling immutable ExecutionEvent:ProducerProcess:3:9daed8ea-dcbe-11ea-a69c-507b9dc4ed46
c.e.w.events.CamundaEventListeners : Handling mutable DelegateExecution:Start
c.e.w.events.CamundaEventListeners : Handling immutable ExecutionEvent:ProducerProcess:3:9daed8ea-dcbe-11ea-a69c-507b9dc4ed46
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:start
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:create
c.e.w.events.CamundaEventListeners : Handling mutable DelegateExecution:Producer
c.e.w.events.CamundaEventListeners : Handling immutable ExecutionEvent:ProducerProcess:3:9daed8ea-dcbe-11ea-a69c-507b9dc4ed46
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:add-identity-link
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:create
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:update
c.e.w.events.CamundaEventListeners : Handling mutable DelegateTask:Activity_15yh7ii
c.e.w.events.CamundaEventListeners : Handling immutable TaskEvent:Activity_15yh7ii
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:update
c.e.w.events.CamundaEventListeners : Handling mutable DelegateTask:Activity_15yh7ii
c.e.w.events.CamundaEventListeners : Handling immutable TaskEvent:Activity_15yh7ii
c.e.w.events.CamundaEventListeners : Handling mutable HistoryEvent:update

All the events are triggered properly.

2 Likes

@aravindhrs Thanks, yes the events work when I don’t have the camunda.cfg.xml file, but I also would like to attach a listener when a bpmn is parsed on deployment. For this, I need to add a plugin and configuration in cfg.xml. Is there a way to achieve both of these functionalities (process event listener, parse listener) without adding the xml file?

If you configure the below class as Bean it will get registered as plugins with process engine.

com.example.workflow.service.parseListener.ProgressLoggingSupportParseListenerPlugin

So you don’t need to have cfg.xml file in Spring based applications