Search code examples
camunda

Squence generator for camunda


How can I set my own IdGenerator for camunda via processes.xml. Before switching to using processes.xml, I used

  ProcessEngineConfiguration.setIdGenerator(IdGenerator);

Which uses a sequence of a oracle database.


Solution

  • 1) Implement a ProcessEnginePlugin

        package com.example;
        
        import org.camunda.bpm.engine.ProcessEngine;
        import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
        import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin;
        
        public class IdGeneratorPlugin implements ProcessEnginePlugin {
        
          public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
            processEngineConfiguration.setIdGenerator(new CustomIdGenerator());
          }
    
          public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
          }
        
          public void postProcessEngineBuild(ProcessEngine processEngine) {
          }
        }
    

    2) Register the plugin in processes.xml

        <?xml version="1.0" encoding="UTF-8"?>
        <process-application
          xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.camunda.org/schema/1.0/ProcessApplication http://www.camunda.org/schema/1.0/ProcessApplication ">
    
          <process-engine name="default">
            ...
            <properties>
              ...
            </properties>
    
            <plugins>
              <plugin>
                <class>com.example.IdGeneratorPlugin</class>
              </plugin>
            </plugins>
          </process-engine>
    
          <process-archive name="pa">
            <properties>
              ...
            </properties>
          </process-archive>
        </process-application>
    

    3) Make sure the plugin is on the camunda-engine classpath or the classpath of your process application

    Source: https://docs.camunda.org/manual/7.3/api-references/deployment-descriptors/#descriptors-processesxml