Split webapps and logic / worker in seperate JAVA application

Hi,

I am trying to setup a heterogeneous cluster with the community edition. Before I setup a kubernetes cluster I was trying to test this functionality with two local JAVA applications.

At the beginning I create a JAVA project using https://start.camunda.com.

  • Group: com.myapplication.camunda.webapps
  • Artifact: application
  • Camunda Platform Version: 7.15.0
  • Spring Boot Version: 2.4.3
  • H2 Database: On-Disk (will be replaced later with MySQL)
  • Java Version: 11
  • Camund Platform Modules: REST API, Webapps, Spin (XML & JSON)
  • Spring Boot Modules: nothing

I extract the zip file and open it in IntelliJ. After that I do the following steps:

  1. Change the JDK to openJDK 16
  2. Create a JAVA class com.myapplication.camunda.webapps.worker.GetNumber (implements JavaDelegate) with the following function:
    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        delegateExecution.setVariable("value", 12);
    }
  1. Replace the H2 dpendency in the pom.xml with the following:
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.26</version>
    </dependency>
  1. Change the database settings in the application.yaml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/camunda?sendFractionalSeconds=false
    username: camunda
    password: Secret-Passw0rd
    driver-class-name: com.mysql.cj.jdbc.Driver

camunda.bpm.admin-user:
  id: demo
  password: demo
  1. Modify the bpmn file to the following structure:

image

start → user task → service task (JAVA class → com.myapplication.camunda.webapps.worker.GetNumber) → user task → end

When I start the application, everything works. I can open http://localhost:8080, open task list, start a new process confirm the first user task, and when I open the last user task, I see the “value = 12”.

So far, so good.

Now I want to split the webapps from business logic and bpmn file.

I create a second application using http://start.camunda.com, but this time without the camunda webapps.

  • Group: com.myapplication.camunda.logic
  • Artifact: quiz
  • Camunda Platform Version: 7.15.0
  • Spring Boot Version: 2.4.3
  • H2 Database: On-Disk (will be replaced later with MySQL)
  • Java Version: 11
  • Camund Platform Modules: REST API, Spin (XML & JSON)
  • Spring Boot Modules: nothing

I change the SDK to openJDK 16 and the server.port to 8090 in the application.yaml. The database connection and pom dependency will be changed similar to the application project.

I copy the bpmn file and the worker.GetNumber class from the application project to the quiz project. After that I delete both files from the application project.

In the GetNumber class I change the returnin number from 12 to 13 (just to see if the correct class is called). I paste the new JAVA class reference to the bpm service task.

Now I start both applications and open the task tasklist on localhost:8080. I start a new process, claim and complete the task an I get an error message:

An error happened while submitting the task form : Cannot submit task form d620a29e-0e53-11ec-9f2c-1623875a5188: ENGINE-09008 Exception while instantiating class 'com.myapplication.camunda.logic.worker.GetNumber': ENGINE-09017 Cannot load class 'com.myapplication.camunda.logic.worker.GetNumber': com.myapplication.camunda.logic.worker.GetNumber

I know, that I have to set asynchronous before / after in the bpmn file, and I think I have to implement Tasklistener - somewhere.

I have already seen the youtube video from CamundaCon 2018, but I didn’t get it work with the current Camunda / openJDK version (CamundaCon 2018: Camunda In A Heterogeneous Cluster (Generali) - YouTube).

Can someone help me to get the quiz worker working?

Thanks in advance and best regards,

Rainer

If you will have one application only with the webapp part, without the java delegates classes, you need to disable the job executor from it, so it stops to get jobs at database. You need to set Async after in your User task too, so when you complete a task by Tasklist, it will create a new job in database, and let the other project that still has the job executor active and the correct java classes will handle it.

If you let your application with default settings, the job acquisition is enabled by default. So it will take jobs from database and try to execute the javaclasses, wich doesnt exist in this class path, right? the same will happen when you try to complete a user task without Async After, coz it will try to run the next steps within same Database Transaction, in the same java application, wich doesnt have the classes nedded.

Try it setting this property in your bootstrap.yml of the only webapplication java project:

camunda:
  bpm:
    job-execution:
      enabled: false

And dont forget to set async after on your user tasks:
Screen Shot 2021-09-06 at 03.32.39

1 Like

Thank you very much … the job-execution setting was the missing one!

1 Like