I have implemented a java worker for completing service BPMN tasks.
What I need to achieve is to return a variable from the java worker code to the engine.
I can fetch a process variable (for example, the process variable “name”) into the java worker, like this:
String name= (String) externalTask.getVariable(“name”);
how can I return back to the engine one variable that is defined inside the java worker code?
Somthing like the following, it doesn’t work: externalTask.setVariable(“number”);
Generally speaking about implementing a service BPMN task, is there any difference between implementation with a java class and an external worker? Since, I do not have technical background, they seem to me more or less the same. Is there any concrete distinction between them that can guide me what to select in each case that I face?
I would appreciate any comments and any help on these questions.
External Workers are external programs that communication with camunda via REST-API.
JavaClasses have to be added in your camunda java-project and deployed (e.g. war file). They are used directly by the camunda-instance when needed.
So in case of an external worker you use this API to complete a task and in the same request you are able to append variables to attach (or update) in your process-instance:
Since external tasks don’t block any camunda-workerthreads, they are the recommended way for implementing long running tasks.
client.subscribe("topicName", async function({ task, taskService }) {
// get the process variable 'score'
const score = task.variables.get("score");
// set a process variable 'winning'
const processVariables = new Variables();
processVariables.set("winning", score > 5);
// set a local variable 'winningDate'
const localVariables = new Variables();
localVariables.set("winningDate", new Date());
// complete the task
await taskService.complete(task, processVariables, localVariables);
});
I don’t know.
In what kind of program is this code executed, which classes did you import (what stands behind die externalTaskService-Object and it functions)?
I did just work with C# external task workers, and those just use REST-API (of course also behind helper functions)…