hi All
I am trying to retrieve the list of objects from worker service to the start task. I am able to the object but I am unable to get the list of objects.
@PostMapping(value = "api/v1/test/camunda")
public List<ResponseDto> test(@RequestParam(name = "input", required = true) String value) {
try {
// Create a JSON object and add the string value
JSONObject jsonObject = new JSONObject();
jsonObject.put("input", value);
client.newDeployResourceCommand().addResourceFromClasspath("test2.bpmn").send().join();
final ProcessInstanceResult event = client.newCreateInstanceCommand().bpmnProcessId("Process_0hyn9df")
.latestVersion().variables(jsonObject.toString()).withResult().send().join();
List<ResponseDto> responseDto = (List<TenantCompanyDetailsDto>) event
.getVariablesAsType(ResponseDto.class);
log.debug(responseDto.toString());
return responseDto;
} catch (Exception e) {
e.printStackTrace();
log.debug("Exception " + e.getMessage());
return Collections.emptyList();
}
}
Worker
@ZeebeWorker(type = "getUserDetails")
public void test(final ActivatedJob job, @ZeebeVariable String value) {
log.debug("worker job called to get information from cache service ");
List<ResponseDto> responseDto = // business logic outcome
client.newCompleteCommand(job.getKey()).variables(responseDto).send();
}
I am unable to retrieve the responseDto in the controller. My log is not getting printed. I am getting error as below,
io.camunda.zeebe.client.api.command.ClientStatusException: Time out between gateway and broker: Request ProtocolRequest{id=18979, subject=command-api-1, sender=172.18.0.3:26502, payload=byte{length=167, hash=353903838}} to 172.18.0.3:26501 timed out in PT10S
at io.camunda.zeebe.client.impl.ZeebeClientFutureImpl.transformExecutionException(ZeebeClientFutureImpl.java:93)
at io.camunda.zeebe.client.impl.ZeebeClientFutureImpl.join(ZeebeClientFutureImpl.java:50)
at com.bosch.ms.orchestration.controller.EntryPointController.test(EntryPointController.java:36)
What I want to achieve is to get the object which was set in worker service in controller. Need experts advice.
@jwulf or @Ingo_Richtsmeier could you help here?
Remove the .withResult() from your Start Process Call
@PostMapping(value = "api/v1/test/camunda")
public List<ResponseDto> test(@RequestParam(name = "input", required = true) String value) {
try {
// Create a JSON object and add the string value
JSONObject jsonObject = new JSONObject();
jsonObject.put("input", value);
client.newDeployResourceCommand().addResourceFromClasspath("test2.bpmn").send().join();
final ProcessInstanceResult event = client.newCreateInstanceCommand()
.bpmnProcessId("Process_0hyn9df")
.latestVersion()
.variables(jsonObject.toString())
.withResult() <-- This is causing your Gateway Timeout
.send()
.join();
List<ResponseDto> responseDto = (List<TenantCompanyDetailsDto>) event
.getVariablesAsType(ResponseDto.class);
log.debug(responseDto.toString());
return responseDto;
} catch (Exception e) {
e.printStackTrace();
log.debug("Exception " + e.getMessage());
return Collections.emptyList();
}
}
But… your process should still be getting activated, which means your worker should still be getting tripped. (Ie the error you posted is an expected ignorable error that is NOT related to your worker not working … it’s actually likely the other way around – the Worker not running is causing your process to run for more then 10s)
Could you also port your BPMN file? The worker type in the BPMN file and the annotation must match exactly.
Your worker MUST NOT be part of the same code that is running postmapping, as they need to both be running at the same time.
@GotnOGuts If I am doing Async how will I get the response of a worker task? If there is any code snippet shared that would be helpful.
As is mentioned in your other thread it’s difficult to go from async to sync responses.
It’s generally not a good idea to create multiple threads on the same topic, without at least mentioning that you have other threads on the topic on the go. Conversations on the topic get mixed up, and you’ll get different recommendations on different threads, which will cause you confusion.
After your newCreateInstanceCommand, you can poll the Zeebe engine in a while loop to find the status of your process before returning the response to your UI client. I’d recommend some sort of sleep in that loop, so that you’re not hammering the gateway.
As mentioned in my prior reply, if you expect your process to return back in under 10s, then what you are doing should be fine… if you have your worker set up correctly. Which brings us back to the prior request - please post the test2.bpmn