ExecutionQuery by processInstanceBusinessKey


The following code works:
Execution execution = runtimeService.createExecutionQuery()
runtimeService.messageEventReceived(“someSubscription”, execution.getId());

But this one results in a NPE on messageEventReceived line:
(the process was started using this business key)
runtimeService.messageEventReceived(“someSubscription”, execution.getId());

The following code works, so the business key is correct:
ProcessInstance anInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(“SomeBusinessKey”).singleResult();

The business key is only set on the process instance execution, and not on child executions. Hence why the combination of business Key + message event subscription doesn’t work as there is no matching execution.
You will have to use 2 queries for this: first for the process instance and then one for the actual execution, using the processInstanceId from the first query.