Shared process engine, process.xml and spring

Hello,
I have the following scenario:

  • Camunda 7.8.0-ee
  • Wildfly
    • Cluster 1
    • Cluster 2
      Here I my standalone.xml
    <subsystem xmlns="urn:org.camunda.bpm.jboss:1.1">
        <process-engines>
            <process-engine name="default" default="true">
                <datasource>java:jboss/datasources/ProcessEngine</datasource>
                <history-level>full</history-level>
                <properties>
                    <property name="jobExecutorAcquisitionName">
                        default
                    </property>
                    <property name="isAutoSchemaUpdate">
                        false
                    </property>
                    <property name="authorizationEnabled">
                        true
                    </property>
                    <property name="jobExecutorDeploymentAware">
                        true
                    </property>
                </properties>
                <plugins>
                    <plugin>
                        <class>org.camunda.bpm.application.impl.event.ProcessApplicationEventListenerPlugin</class>
                    </plugin>
                    <plugin>
                        <class>org.camunda.spin.plugin.impl.SpinProcessEnginePlugin</class>
                    </plugin>
                    <plugin>
                        <class>org.camunda.connect.plugin.impl.ConnectProcessEnginePlugin</class>
                    </plugin>
                </plugins>
            </process-engine>
        </process-engines>
        <job-executor>
            <core-threads>3</core-threads>
            <max-threads>5</max-threads>
            <queue-length>10</queue-length>
            <job-acquisitions>
                <job-acquisition name="default">
                    <properties>
                        <property name="lockTimeInMillis">
                            300000
                        </property>
                        <property name="waitTimeInMillis">
                            5000
                        </property>
                        <property name="maxJobsPerAcquisition">
                            3
                        </property>
                    </properties>
                </job-acquisition>
            </job-acquisitions>
        </job-executor>
    </subsystem>
  • Microservice with a new .bpmn process using the current Camunda database (just to continue using the same Cockpit) and embedded tomcat
    • MyApplication.class
public class MyApplication{
    public static void main(String... args) {
        SpringApplication.run(MyApplication.class, args);
    }

    @PostDeploy
    public void onDeploymentFinished(ProcessEngine processEngine) {
        try {
            SpringProcessEngineConfiguration processEngineConfiguration = (SpringProcessEngineConfiguration) processEngine.getProcessEngineConfiguration();
            processEngineConfiguration.setDefaultSerializationFormat("application/json");

            List<IncidentHandler> customIncidentHandlers = new ArrayList<>();
            customIncidentHandlers.add(new CustomIncidentHandler(Incident.FAILED_JOB_HANDLER_TYPE));
            customIncidentHandlers.add(new CustomIncidentHandler(Incident.EXTERNAL_TASK_HANDLER_TYPE));
            processEngineConfiguration.setCustomIncidentHandlers(customIncidentHandlers);

        } catch (Throwable e) {
            throw e;
        }
    }
}
  • process.xml
  <process-archive name="myAppEngine">
    <process-engine>default</process-engine>
    <properties>
        <property name="isDeleteUponUndeploy">false</property>
        <property name="isScanForProcessDefinitions">true</property>
        <property name="jobExecutorDeploymentAware">true</property>
    </properties>
  </process-archive>

The ideia is to use the same process engine(default), but when I start the application, jobExecutorDeploymentAware doesn’t work. Affecting the job executor pool, because my application started getting jobs from the other processes.
@PostDeploy doesn’t work too, so I couldn’t use my custom Incident Handler.

To workaround those issues I had to change MyApplication.class to:

@SpringBootApplication
public class MyApplication {

And create the following config file:

@Configuration
@Import( {SpringProcessEngineServicesConfiguration.class})
public class ProcessEngineConfig {

    @Value("${camunda.bpm.history-level:full}")
    private String historyLevel;
    private DataSource dataSource;
    private ResourcePatternResolver resourceLoader;

    public ProcessEngineConfig(DataSource dataSource, ResourcePatternResolver resourceLoader) {
        this.dataSource = dataSource;
        this.resourceLoader = resourceLoader;
    }

    @Bean
    public SpringProcessEngineConfiguration processEngineConfiguration() throws IOException {
        SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();

        config.setDataSource(dataSource);
        config.setTransactionManager(transactionManager());
        config.setHistory(historyLevel);

        config.setDefaultSerializationFormat("application/json");

        List<IncidentHandler> customIncidentHandlers = new ArrayList<>();
        customIncidentHandlers.add(new CustomIncidentHandler(Incident.FAILED_JOB_HANDLER_TYPE));
        customIncidentHandlers.add(new CustomIncidentHandler(Incident.EXTERNAL_TASK_HANDLER_TYPE));
        config.setCustomIncidentHandlers(customIncidentHandlers);

        config.setCreateIncidentOnFailedJobEnabled(true);
        config.setJobExecutorActivate(true);
        config.setMetricsEnabled(false);
        config.setJobExecutorDeploymentAware(true);

        // deploy all processes from folder 'bpmn'
        Resource[] resources = resourceLoader.getResources("classpath:/bpmn/*.bpmn");
        config.setDeploymentResources(resources);

        return config;
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public ProcessEngineFactoryBean processEngine() throws IOException {
        ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
        factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
        return factoryBean;
    }

}

Do you think is that the best way to do that? Why I couldn’t use process.xml to set some configs?
Why @PostDeploy doesn’t work?

Thanks in advance.

@regissantana

camunda-spring-boot-starter is configured to use the SpringProcessEngineConfiguration auto deployment feature.

Also you need to add @EnableProcessApplication to your spring boot application.

@SpringBootApplication
@EnableProcessApplication("myProcessApplicationName")
public class MyApplication {

...

}

When using @EnableProcessApplication we don’t extend the ProcessApplication class, we can’t use @PostDeploy and @PreUndeploy method annotations. Instead these callbacks are provided via Spring event publishing mechanism. So you can use the following event listeners:

@EventListener
public void onPostDeploy(PostDeployEvent event) {
 ...
}

@EventListener
public void onPreUndeploy(PreUndeployEvent event) {
 ...
}

Also you disabled <property name="isAutoSchemaUpdate"> false</property> . So before running your process application make sure that you have schema and tables are in place.