I have CallActivity task in my process that calls another process (another bpmn file) and this process has its own processInstanceId. How can I get the processInstanseId of process which was called by CallActicity task if I have the processInctanceId of main process (that contains that CallActivity task)?
I start my process as follows:
...
runtimeService.startProcessInstanceByKey(processKey, variablesMap);
The CallActivity task in the main process calls another process which has Receive Task. And I need to send a signal on this Receive Task as follows:
runtimeService.signal(processId, variablesMap);
But I have only processInstanceId of main process. Is there a way to get a processInstanceId of CallActivity process by processInstanceId of main process from java code?
Thank you in advance.
Hi @korobikhina,
I would use the message correlation to send messages to the engine: https://docs.camunda.org/manual/7.9/reference/bpmn20/events/message-events/#using-the-runtime-service-s-correlation-methods. Here you don’t need the process instance id and you can use the business key or variables to find the receiving process instance.
Signaling is misleading, as Camunda supports the signal event as well and the signal event is for broadcasting: https://docs.camunda.org/manual/7.9/reference/bpmn20/events/signal-events/#signal-api.
Hope this helps, Ingo
Hi @Ingo_Richtsmeier
Thank you for the answer.
I’ve tried to use the message correlation as follows:
runtimeService.createMessageCorrelation("messageName")
.processInstanceBusinessKey("businessKey")
.setVariable(paramsMap)
.correlate();
If there are multiple instances of process which are waiting on Receive Task (messageName and businessKey are the same for each instance), the message will be sent to all these instances, right?
Hi @korobikhina,
The BPMN spec states that messages are always a one-to-one relationship. So you will get a MismatchingMessageCorrelationException
if none or more than one process instances can receive the message. Signals are broadcasted to all recipients.
But Camunda contains runtimeService.createMessageCorrelation("messageName").correlateAll()
to deliver a message to more than one recipient.
Cheers, Ingo
@Ingo_Richtsmeier OK, I’ve got.
Thank you very much for your help)