Embedding Camunda into an existing Java application

大憨熊 提交于 2020-12-13 07:35:27

问题


I have pulled the Camunda latest image and running Camunda in it's own docker container. I have a dmn uploaded to Camunda Cockpit and I am able to make Rest calls to get data from the decision table that I have uploaded to the Camunda Cockpit. However, I do not want to depend on Camunda running independently. I have an existing huge application(a micro-service running in it's own docker container) and I want to embed Camunda into my micro-service (that uses Osgi, Java, Docker, Maven, etc.). Can someone please guide me with this?


回答1:


For a Spring Boot micro service you can add the required starter and config files to your deployment and should be good to go. See e.g. https://start.camunda.com/ to get everything you need. You can then access Camunda via Java API or REST (if starter was included).

If you do not run in a Spring Boot environment then the way of bootstrapping Camunda may differ. In plain Java, without any container usage it would be along those lines:

ProcessEngine processEngine = ProcessEngineConfiguration
    .createStandaloneProcessEngineConfiguration()
    .setJdbcUrl("jdbc:h2:./camunda-db/process-engine;DB_CLOSE_DELAY=1000")
    .setDatabaseSchemaUpdate("true")
    .setJobExecutorActivate(true)
    .buildProcessEngine();

processEngine.getRepositoryService()
    .createDeployment()
    .addClasspathResource("myProcess.bpmn")
    .deploy();
    
ProcessInstance pi = processEngine.getRuntimeService()
    .startProcessInstanceByKey("myProcess");

In a standard Spring environment you would bootstrap the engine by loading the context:

ClassPathXmlApplicationContext applicationContext = 
    new ClassPathXmlApplicationContext("/spring-context.xml");
ProcessEngine processEngine = (ProcessEngine) applicationContext.getBean("processEngine");
    
processEngine.getRepositoryService()
    .createDeployment()
    .addClasspathResource("myProcess.bpmn")
    .deploy();

Also see: https://docs.camunda.org/manual/latest/user-guide/process-engine/process-engine-bootstrapping/

https://docs.camunda.org/get-started/quick-start/install/

Update based on comment:

The Camunda OSGI support is described here: https://github.com/camunda/camunda-bpm-platform-osgi

You would need to upgrade the project to a more recent version, which is likely not a huge effort as the version have remained compatible.

(I would also encourage you to consider migrating the micro service to Spring Boot instead. Complexity, available knowledge in the market, support lifetime,..)



来源:https://stackoverflow.com/questions/64880500/embedding-camunda-into-an-existing-java-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!