JavaDelegate and spring-boot microservices architecture design

I am currently building a spring-boot microservice using Camunda to orchestrate different microservices to store different parts or a whole POST request body. This orchestration service has several stages.

Example POST request body made towards the orchestration service:

{
 "variables:" {
    "object1" : "example json String",
    "object2" : "another example json String"
  }
}

stage 1: extract object1 and make a REST call to a microservice.
stage 2: extract object2 and make a REST call to different microservice
stage 3: extract both object1 & object2 and store them within a database
stage 4: extract both object1 & object2 and make a REST call to a final microservice.

Currently the way I’m doing it is to have 4 separate classes which implement JavaDelegate to each execute one stage each. This way I can track more easily on the BPMN diagram which JavaDelegate class it is in, with each service task corresponding to a JavaDelegate class. But I don’t like how I have to keep extracting the data and unmarshalling into objects in each JavaDelegate class to be sent on to the relevant microservices when a previous class has done it before.

Is it possible to have one JavaDelegate method which deals with extracting the object and then sending the needed part onwards to service classes, with Camunda still tracking those service classes? If so, how would I do that?

Hi @wseaford,

you have two options:

  1. Add a JavaDelegate at the beginning of your process to transform the input data to the Java objects you expect in the following steps and save them as process variables. (Your proposal)
  2. Extend your Java Delegates from a superclass where you collect all nessessary data transformations.

Hope this helps, Ingo

thank you for replying! @Ingo_Richtsmeier

In the first scenario. By having one service task in my bpmn diagram connected to orchestrating Java class using JavaDelegate. How would I track on the bpmn graph that it is in another class called by the orchestrating class? would I annotate all tasks on a bpmn as service tasks with a corresponding Java class?

Hi @wseaford,

I assumed that you implement every step as a service task in your bpmn file.

Then you can implement the logic for each task either in a java class: https://docs.camunda.org/manual/7.10/user-guide/process-engine/delegation-code/.

The tasks will usually communicate with process variables: You pass some variables with the start, each delegate implementation will pick them up and add one or more new variables with the result of the service call.

You wire the Java class naming them in the service task: https://docs.camunda.org/manual/7.10/reference/bpmn20/tasks/service-task/.

The internal structure of your code is not relevant. An easy approach is to put a new class in each service task.

But in theory it’s also possible to write one very generic Java class and control it with field injection (https://docs.camunda.org/manual/7.10/user-guide/process-engine/delegation-code/#field-injection) and input-mapping (https://docs.camunda.org/manual/7.10/user-guide/process-engine/variables/#input-output-variable-mapping).

To ease the maintenance I would write a new class for each service task.

Hope this helps, Ingo