Search code examples
javacamunda

Why does Camunda generate a numeric process instance ID, instead of UUID?


Camunda normally uses UUIDs (e. g. 98631715-0b07-11ec-ab3b-68545a6e5055) as process instance IDs. In my project a process instance ID like 124 is being generated which looks suspicious to me.

This behavior can be reproduced as described below.

Step 1

Check out this repository and start the process engines

so that all of them use the same shared database.

Step 2

Login to the Camunda UI at http://localhost:8080 and navigate to the tasklist.

Start the Starter process in tasklist.

Starting a process

Starting a process

Step 3

Go to the cockpit and navigate to Running process instances (http://localhost:8080/camunda/app/cockpit/default/#/processes).

Running processes

Click on DomainProcess.

Process with a numeric process instance ID

In column ID you will see a numeric (135 in the screenshot above) process instance ID, not a UUID.

Probable cause of the error

In core-processs engine I have the following Config class:

import org.camunda.bpm.engine.impl.history.HistoryLevel;
import org.camunda.bpm.engine.impl.history.event.HistoryEvent;
import org.camunda.bpm.engine.impl.history.handler.CompositeHistoryEventHandler;
import org.camunda.bpm.engine.impl.history.handler.HistoryEventHandler;
import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

import static org.apache.commons.lang3.ArrayUtils.addAll;

@Configuration
public class Config {
    private static final Logger LOGGER = LoggerFactory.getLogger(Config.class);

    @Autowired
    @Qualifier("camundaBpmDataSource")
    private DataSource dataSource;

    @Autowired
    @Qualifier("camundaTxManager")
    private PlatformTransactionManager txManager;

    @Autowired
    private ResourcePatternResolver resourceLoader;

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

        config.setDataSource(dataSource);
        config.setTransactionManager(txManager);
        config.setDatabaseSchemaUpdate("true");

        config.setHistory(HistoryLevel.HISTORY_LEVEL_FULL.getName());
        config.setJobExecutorActivate(true);
        config.setMetricsEnabled(false);
        final Logger logger = LoggerFactory.getLogger("History Event Handler");

        final HistoryEventHandler testHistoryEventHandler = new HistoryEventHandler() {

            @Override
            public void handleEvent(final HistoryEvent evt) {
                LOGGER.debug("handleEvent | " + evt.getProcessInstanceId() + " | "
                        + evt.toString());
            }

            @Override
            public void handleEvents(final List<HistoryEvent> events) {
                for (final HistoryEvent curEvent : events) {
                    handleEvent(curEvent);
                }
            }
        };

        config.setHistoryEventHandler(new CompositeHistoryEventHandler(Collections.singletonList(testHistoryEventHandler)));

        try {
            final Resource[] bpmnResources = resourceLoader.getResources("classpath:*.bpmn");
            final Resource[] dmnResources = resourceLoader.getResources("classpath:*.dmn");
            config.setDeploymentResources(addAll(bpmnResources, dmnResources));
        } catch (final IOException exception) {
            exception.printStackTrace();
            LOGGER.error("An error occurred while trying to deploy BPMN and DMN files", exception);
        }

        return config;
    }
}

If I remove this configuration (or comment the @Configuration line), the error disappears.

Questions

Why does Camunda generate a numeric process instance ID in this case (and not a UUID as in other cases)?


Solution

  • After adding the line

    config.setIdGenerator(new StrongUuidGenerator());
    

    in the configuration class

        @Bean
        public SpringProcessEngineConfiguration processEngineConfiguration() {
            final SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
            config.setIdGenerator(new StrongUuidGenerator());
            config.setDataSource(dataSource);
    

    the process instance IDs became UUIDs again.

    For details see Camunda documentation on ID generators.