How to avoid passing process variables across tasks

In camunda 8, say, I have 10 service tasks, each service task has output variable.
Say, first task has output variable as x and second task has output variable of y.
I dont want x or y to be sent as input to service task 10. I can see an option in camunda 7 but I couldn’t figure out in 8. We have so many process variables and trying to avoid lot of movement of process variables.
One option i can think is to wrap task in a event subprocess. Is this the best option?

Please advise.


In your Job Worker (the implementation of the service task) you can specify which variables to receive and no more than that. For example in Java/Spring:

@JobWorker(type = “publish-tweet”)
public void handleTweet(@VariablesAsType TwitterProcessVariables variables)

See camunda-8-examples/twitter-review-java-springboot/src/main/java/org/camunda/community/examples/twitter/process/ at 61e76223b2b81ee39da409b9d572cefcf4d00307 · camunda-community-hub/camunda-8-examples · GitHub for an example.



1 Like

Sorry for late respond.
I tried your solution and it works but doesn’t fully solve my purpose.
here is my typical worker looks like with ActivatedJob as I needed for retries and additional logic. I added as you suggested and I am getting the required variable but I also need ActivatedJob and when i do that, it is getting everything(outputs from previous service tasks).

Or Does it mean that, when I use job.getVariablesAsMap as I was using previously, camunda makes a internal call to fetch all variables that has potential to degrade the performance. I am not 100% sure of internal implementation. So, never call job.getVariablesAsMap even though ActivatedJob is passed in method signature and pass VariablesAsType. Is my understanding correct?

public class DummyWorker2 {
private final static Logger logger = LoggerFactory.getLogger(DummyWorker2.class);

@JobWorker(type = “dummyWorker2”, autoComplete = true)
public Map<String, Object> printDummy(@VariablesAsType RegIdVariableModel variables, final ActivatedJob job) {

  Map<String, Object> input = job.getVariablesAsMap();"dummyWorker input: " + input);"dummyWorker variables: " + variables.getRegId());

  Map<String, Object> out = new HashMap<>();
  out.put("dummy", true);
  return out;



Hi @JG2023

Below docs might be of help to you.

1 Like

Thanks. It worked.

@JobWorker(type = “dummyWorker2”, autoComplete = true, fetchVariables={“userId”})

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.