camunda 的序列生成器

Squence generator for camunda

如何通过 processes.xml 为 camunda 设置我自己的 IdGenerator。 在切换到使用 processes.xml 之前,我使用了

  ProcessEngineConfiguration.setIdGenerator(IdGenerator);

其中使用了oracle数据库的序列。

1) 实现一个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) 在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) 确保插件位于 camunda-engine 类路径或进程应用程序的类路径中

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