ParseListener spring boot starter configuration

Hello, I am trying to implement parse listener with spring boot starter and somehow i am not able to make it work. Any help would be greatly appreciated.

Here is what i have tried so far. Please note that i have very basic Spring Boot application without any customization and trying to add plugin to default process engine configuration instead of changing or overriding it.

------------------------------ option 1 — java bean way-------------------------------

@Configuration
public class ProcessEnginePluginConfiguration {

@Bean
@Order(Ordering.DEFAULT_ORDER + 1)
public static ProcessEnginePlugin myProcessEnginePluginConfiguration() {
	return new ProgressModelParseListenerPlugin();
}

}

public class ProgressModelParseListenerPlugin extends AbstractProcessEnginePlugin {
---------------------------------------
}

--------------------------------------- option 2 – camunda.cfg.xml way ---------------------------------

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
<property name="processEnginePlugins">
  <list>
	<bean class="***.ProgressModelParseListenerPlugin " />
  </list>
</property>
</bean>

@bom To activate the BPMN Parse Listener Plugin, you need to register the bean like below:

The BPMN Parse Listener can be activated in the camunda.cfg.xml :

<!-- activate bpmn parse listener as process engine plugin --> 
<property name="processEnginePlugins"> 
  <list>
    <bean 
      class="org.camunda.bpm.example.parselistener.ProgressLoggingSupportParseListenerPlugin" /> 
    </list>
 </property>

Refer the below example to Activate the BPMN Parse Listener Plugin:

Thanks @aravindhrs

When i created spring boot application it didn’t create camunda.cfg.xml file so i created new one in resources/META-INF folder like below. Am i making any mistake here?

Also, couldn’t find default camunda.cfg.xml for spring boot application. is there one out there?

<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
<property name="processEnginePlugins">
  <list>
	<bean class="***.ProgressModelParseListenerPlugin " />
  </list>
</property>
</bean>

Hi @bom,

Camunda Spring Boot didn’t use the camunda.cfg.xml. A process engine plugin has to set by code as described here: https://docs.camunda.org/manual/7.13/user-guide/spring-boot-integration/configuration/#adding-additional-configurations.

I recently answered another thread with a similar topic: IncidentHandler - Using Spring Boot

Hope that helps, Ingo

Thanks @Ingo_Richtsmeier

I tried that option as well. my bean implementation looks like below. ProgressModelParseListenerPlugin is the class that extends AbstractProcessEnginePlugin

@Configuration
public class ProcessEnginePluginConfiguration {

@Bean
@Order(Ordering.DEFAULT_ORDER + 1)
public static ProcessEnginePlugin myProcessEnginePluginConfiguration() {
	return new ProgressModelParseListenerPlugin();
}

I am sure i am making some silly mistake but new to camunda so struggling to figure it out.

I was able to register bean like below but now my parse listener is not getting triggered. Do parse listener and execution listener has to be @Component as well?

@Component
@Order(Ordering.DEFAULT_ORDER + 1)
public class ProgressModelParseListenerPlugin extends AbstractProcessEnginePlugin {

private static final Logger LOGGER = LoggerFactory.getLogger(ProgressModelParseListenerPlugin.class);

@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
	
	LOGGER.debug("inside preInit");
	
    // get all existing preParseListeners
    List < BpmnParseListener > preParseListeners = processEngineConfiguration.getPreParseListeners();

    if (preParseListeners == null) {
        // if no preParseListener exists, create new list
        preParseListeners = new ArrayList < BpmnParseListener > ();
        processEngineConfiguration.setPreParseListeners(preParseListeners);
    }

    // add new BPMN Parse Listener
    preParseListeners.add(new ProgressModelParseListener());
}

}

Hello @Ingo_Richtsmeier ,

Is it possible to have multiple ProcessEnginePlugin configuration classes, and choose which one to use when starting a process from the RuntimeService (java)?

Right now I am starting a process using Springboot in the following way:

...
RuntimeService runtimeService = ProcessEngines.getDefaultProcessEngine().getRuntimeService();
ProcessInstanceWithVariables process;
process = runtimeService.createProcessInstanceByKey(processKey).execute()
...

I have two plugin classes, one which sets all bpmn elements to asyncBefore = false, and one which sets asyncBefore = true. Below is the code:

@Component
@Order(Ordering.DEFAULT_ORDER + 1)
@Slf4j
public class DefaultPlugin extends AbstractProcessEnginePlugin {

    @Override
    public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
        List<BpmnParseListener> preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners();
        if (preParseListeners == null) {
            preParseListeners = new ArrayList<>();
            processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
        }
        preParseListeners.add(new Default());
    }
}

@Slf4j
public class Default extends AbstractBpmnParseListener {

    @Override
    public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
        startEventActivity.setAsyncBefore(false);
    }
}

and the second plugin wich sets AsyncBefore = true:

@Component
@Order(Ordering.DEFAULT_ORDER + 2)
@Slf4j
public class AsyncBeforeStartListenerPlugin extends AbstractProcessEnginePlugin {

    @Override
    public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
        List<BpmnParseListener> preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners();
        if (preParseListeners == null) {
            preParseListeners = new ArrayList<>();
            processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
        }
        preParseListeners.add(new AsyncBeforeStartListener());
    }
}

@Slf4j
public class AsyncBeforeStartListener extends AbstractBpmnParseListener {

    @Override
    public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
        startEventActivity.setAsyncBefore(true);
    }
}
1 Like

Hi @nmanitaras,

no, you can’t enable/disable plugins after the process engine is started.

Hope this helps, Ingo

1 Like