Unable to read/write process variables in WebFlux's WebClient reactive chain

Hi @enolive,

A DelegateExecution object is only useful within the thread and callback that you receive it in. It is not useful in other threads, because certain internal logic is bound to a thread (e.g. transaction management, entity caching, etc.). It is not useful outside of a callback, because it is mutable (e.g. when process execution continues, the DelegateExecutions properties will change).

I’m not experienced with reactive programming in general or WebFlux in particular, but one idea is to set the variables via RuntimeService API, which will then use its own transaction, e.g.:

private Consumer<String> storeInProcessVariables(DelegateExecution execution) {
  RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
  String id = execution.getId();

  return joke -> runtimeService.setVariable(id, "jokeText", joke);
}

Note: Since the callback comes from a different thread, there are various race conditions to consider:

  • The process instance may have finished already.
  • The transaction that has created the execution (and triggered the delegate) may not yet have committed.
  • And maybe more :slight_smile:

So this needs to be designed carefully.

Cheers,
Thorben