ProcessInstance not created yet on whenComplete() callback of newCreateInstanceCommand()

Camunda 8.2.1
spring-boot-starter-camunda 8.2.0
zeebe-client-java 8.2.1

I’m using ZeebeClient to start a new process instance. While doing so I want to access the process instance variables on the whenComplete() callback of newCreateInstanceCommand(). Below is the code

        zeebeClient.newCreateInstanceCommand()
                .bpmnProcessId(PROCESS_ID)
                .latestVersion()
                .variables(VARIABLE_OBJECT)
                .send()
                .whenComplete((processInstanceEvent, throwable) -> {
                        Long processInstanceKey = processInstanceEvent.getProcessInstanceKey();
                        // Below operateService uses CamundaOperateClient to search variables                        
                        Map<String, String> processInstanceVariables = operateService.getProcessInstanceVariables(processInstanceKey);
                        System.out.println(processInstanceVariables);
                });

While debugging I found that process instance is not yet created (or atleast not available for querying) when it reaches the whenComplete() callback. I got 404 exception when I tried to get the ProcessInstance object using processInstanceKey in the same callback. However I got the object back when I queried it after Thread.sleep(5000).

Is this an issue? If not is there any way to access the process instance variables inside whenComplete() callback?

Hello @Sankar ,

this is because of a delay between processing in zeebe and processing in Operate.

Is there a reason why you would fetch the process instance instantly in Operate?

Jonathan

Hi @jonathan.lukas
For some reason, I’m not using Tasklist API. Instead I have my own entity having some process/task related details (say processInstanceKey, taskInstanceKey, taskName, assignee) linked to my Business Entity. And I have an API to Iist down the tasklist combining these two entities for the current user.

I do not want to put everything which I want to show in my tasklist, as processInstance variables. So I have a bit of code which listens to various events and synchronises my process entity. This was indeed working fine with Camunda 7. But when I simulated same thing in Camunda 8, it is not working the same way.

I can understand from C8 architecture that Zeebe and Operate (& other components) are independent. However when Zeebe says I’m done, shouldn’t it be actually done from the eyes of other components as well?

Apologies for my delayed response on this thread.

Hello @Sankar ,

the most important question here is:

However when Zeebe says I’m done, shouldn’t it be actually done from the eyes of other components as well?

The answer is no. Here, the cause is that zeebe export processed events, leading to a stream of events that is exported to Elasticsearch. From here, Operate, Tasklist and Optimize are able to use the exported data to calculate the current status of the zeebe.

As this does not happen synchronous, there is a chance that the last event was not already processed by other components, leading to a state where a state change was processed by zeebe, but the resulting event have not yet been processed.

As a workaround, you can wrap the call to Operate into a resilience framework like resilience4j.

I hope this helps

Jonathan

Thanks @jonathan.lukas

I tried using exporter (from camunda community) instead, and it is the same event exported by zeebe which is not synchronous as you described.

And thanks for voting to my alternate option which is to use a resilience framework in my scenario.

2 Likes

Hi @Sankar I’m facing the same problem. Can you share the link export from camunda community?

Hi @nhattvm11, you can search with the keyword “exporter” in camunda community github link Camunda Community Hub · GitHub

1 Like