How to send variables to Zeebe during JobWorker execution?

Hi !
Is it possible to send some information (via variables) to Zeebe during JobWorker execution for a long running job ?
For example to fix some milestones executed in JobWorker or to show the progress bar in Web UI.
If Yes, I would be grateful for a code example.

:wave: Hi @volodya327.

You can set variables via the SetVariables RPC: Zeebe API (gRPC) | Camunda Platform 8 Docs

Map<String, Object> variables = new HashMap<>();
final var key = job.getElementInstanceKey(); // can be the process instance key (as obtained during instance creation), or a given element, such as a service task(see elementInstanceKey on the job message)
zeebeClient.newSetVariablesCommand(key)
        .variables(variables)
        .send();

Or update the variable while completing the job via Complete RPC: Zeebe API (gRPC) | Camunda Platform 8 Docs

Map<String, Object> variables = new HashMap<>();
zeebeClient.newCompleteCommand(job)
        .variables(variables)
        .send();

Hope that helps

Greets
Zhi

1 Like

Hi, @lzgabel !
Thanks for your help !