Execution does not have a subscription to a message event

Hello, I am having trouble with message event. When a message event called “reject” is fired, the process supposes to cancel any current task inside the subprocess and go back to the first one. It was working before, until I changed all the user tasks inside the subprocess to be multi-instance. I am getting the following error.

Does anyone experienced similar behavior with multi-instance user task?

org.activiti.engine.ActivitiException: Execution with id ‘147794’ does not have a subscription to a message event with name ‘reject’
at org.activiti.engine.impl.cmd.MessageEventReceivedCmd.execute(MessageEventReceivedCmd.java:76) ~[flowable-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.cmd.MessageEventReceivedCmd.execute(MessageEventReceivedCmd.java:33) ~[flowable-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.cmd.NeedsActiveExecutionCmd.execute(NeedsActiveExecutionCmd.java:55) ~[flowable-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24) ~[flowable-engine-5.22.0.jar:5.22.0]
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57) ~[flowable-engine-5.22.0.jar:5.22.0]
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47) ~[flowable-spring-5.22.0.jar:5.22.0]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45) ~[flowable-spring-5.22.0.jar:5.22.0]

Here is the process definition.

Hi,

Which execution id are you using for the message event?
Because you changed to multi instance tasks, there will be multiple executions active for the process instance and therefore it’s important that the correct execution id of the embedded sub process is used.

Best regards,

Tijs

Hi Tijs, I am submiting the message to the current active task’s execution id. so you are saying i should submit it to the subprocess’ execution id instead?

How do I get the subprocess execution id from task?

Hi,

Yes indeed. You need the execution id of the message subscription which is on a different scope execution.
You can retrieve the correct execution with the ExecutionQuery on RuntimeService and use the messageEventSubscriptionName and processInstanceId.

Best regards,

Tijs

Thanks, this does work!

runtimeService.createExecutionQuery().processInstanceId(processInstanceId).messageEventSubscriptionName("reject").singleResult();

Hi @kernelogic,

I had met the same issue, could you please show me the BPMN file? How to subscribe a message event?

addition to the previous answers.
you can get the process instance by creating a runtimeService.createProcessInstanceQuery()
in my case, I used the primary key of my process instance to get the specific process instance I wanted.

        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().variableValueEquals("processVariableName", processVariableValue).singleResult();