Why loading processes via repository service fails?

Hi,

I have a SpringBoot application with embeded camunda engine, can someone please explain why the following code fails to load process definitions (i.e. processDefinitions.size()==0 after the code execution)?

                ClassLoader classLoader = Application.class.getClassLoader();
		InputStream firstStream = classLoader.getResourceAsStream("myFirstBpmn.bpmn");
		InputStream secondStream = classLoader.getResourceAsStream("mySecondBpmn.bpmn");

		repositoryService
				.createDeployment()
				.enableDuplicateFiltering(false)
				.name("MY_APP_DEPLOYMENT")
				.tenantId(null)
				.addInputStream("first", firstStream)
				.addInputStream("second", secondStream)
				.deploy();

		processDefinitions = repositoryService.createProcessDefinitionQuery().latestVersion().list();

PS
In case I load process definitions via engine configuration
e.g.

Resource[] bpmnResources = ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:*.bpmn");
springProcessEngineConfiguration.setDeploymentResources(bpmnResources);

//repositoryService.createProcessDefinitionQuery().latestVersion().list() returns 2

Hi @yilativs,

It seems that the execution of

repositoryService
  .createDeployment()
  .enableDuplicateFiltering(false)
  .name("MY_APP_DEPLOYMENT")
  .tenantId(null)
  .addInputStream("first", firstStream)
  .addInputStream("second", secondStream)
  .deploy();

did not succeed.

  • Are the processes myFirstBpmn.bpmn and mySecondBpmn.bpmn marked as executable?
  • What do you mean with “In case I load process definitions via engine configuration”?

Cheers,
Roman

Hello Roman,

It seems that the execution of code did not succeed.

The code provided above does not throw any exception.

Are the processes myFirstBpmn.bpmn and mySecondBpmn.bpmn marked as executable?

Both processes are marked as executable.

What do you mean with “In case I load process definitions via engine configuration”?

Bellow is an example of code that works with same set of process definitions.

@Bean
public ProcessEngineFactoryBean processEngine(PlatformTransactionManager transactionManager, TransactionAwareDataSourceProxy transactionAwareDataSourceProxy,
      ResourceLoader resourceLoader) throws IOException {
   SpringProcessEngineConfiguration springProcessEngineConfiguration = new SpringProcessEngineConfiguration();
   springProcessEngineConfiguration.setProcessEngineName("engine");//what is the purpose of naming engines?
   springProcessEngineConfiguration.setTransactionManager(transactionManager);
   springProcessEngineConfiguration.setDataSource(transactionAwareDataSourceProxy);
   springProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
   springProcessEngineConfiguration.setJobExecutorActivate(true);

   Resource[] bpmnResources = ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath:processes/*.bpmn");
   springProcessEngineConfiguration.setDeploymentResources(bpmnResources);
   ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
   processEngineFactoryBean.setProcessEngineConfiguration(springProcessEngineConfiguration);
   return processEngineFactoryBean;
}

The question remain, why the following code listed below does not work?

repositoryService
  .createDeployment()
  .enableDuplicateFiltering(false)
  .name("MY_APP_DEPLOYMENT")
  .tenantId(null)
  .addInputStream("first", firstStream)
  .addInputStream("second", secondStream)
  .deploy();

What is the proper way of loading processes into Camunda Engine?

It turned out that in case adding .bpmn to “resource name” the code above works
.addInputStream("first.bpmn", firstStream).addInputStream("second.bpmn", secondStream)

Since it doesn’t throw any exception if a resource name doesn’t end with .bpmn, perhaps it is a bug.

Regards,
Vitaliy

Hi @yilativs,

Sorry for my delayed response.

Great that you could solve the problem by your own. I don’t think that this is a bug, since you can deploy more resources than just bpmn (and cmmn and dmn) files.

Cheers,
Roman

Hello Roman,

Don’t you think that good API would either raise an exception?
At least IllegalArgumentException would be nice to have, since it is a RuntimeException and it won’t break backward compatibility even if you still want to support the legact of Tom Baeyens.

A better option would be not letting a developer to make a mistake but preventing it,
i.e. either adding different methods to your DSL
e.g instead of error prone (it’s evident that it is error prone since a person working on a project can not spot an error)

.addInputStream("first.bpmn", firstStream)

use

.addBpmnInputStream("first", firstStream)
.addCmmnInputStream("first", firstStream)
.addDmnsInputStream("first", firstStream)

Regards,
Vitaliy

Hi @yilativs,

in general, I agree with you, but not in that case.

With this API you can deploy different kind resources (scripts, html forms etc.) and not only bpmn, cmmn, or dmn files. Changing it by making it more restricted, we would indeed break the API, since there might be resources which cannot be deployed anymore.

Cheers,
Roman

Hello Roman,

If the API is error prone but can not be changed, than having at least a javadoc explaining such behaviour would be nice to have.

PS Being an opensource developer myself, I gave you feedback and advises how to improve the code,
the rest is up to :wink:

Regards,
Vitaliy

Hi, I have successfully deployed(MY_APP_DEPLOYMENT) a processes application with some bean(service task bean) and it is working fine.

Then I have added one more bpmn like
repositoryService
.createDeployment()
.enableDuplicateFiltering(false)
.name(“MY_APP_DEPLOYMENT”)
.addInputStream(“first”, firstStream)
.deploy();

Here I am facing issue due My recent bpmn not able to find service task bean.
How can I resolve this?