Correlated Message throw does not trigger parent process

Hi

I am trying to correlate a message from a child process that is triggered by a call activity. This child process throws a message. But for some reason, the parent process is not able to catch the message.

I am getting the following error Cannot correlate message 'work': No process definition or execution matches the parameters

The child process throws a message event like this:
${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation("work").processInstanceId(execution.getVariable("parentProcessInstanceId")).setVariable("crqId", "myid").correlate()}

Child process:

Parent process:

Can someone please help me with this? Thanks!

MessageCatch.bpmn (5.8 KB) MessageThrow.bpmn (2.8 KB)

There are a few problems you’ve got. The first is the fact the parent process needs to be waiting at an active message receive event. Which it is not. While the Call Activity is still running the child process it will not move to the message event (as a side note you can remove the event based gateway if there is only one event)

If you want to wait for a message while the sub process is running. use a message boundary event
image

The call your making for messages is not quite right.

Don’t use the process instance id when correlating instead use a business key that you can pass to the sub process.

execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation("work").processInstanceBusinessKey("somekey").correlate();

and finally - make sure you have a transaction boundry in your sub process before you send message. this will ensure the message is persisted to the DB before you try to correlate to it. best done by adding an asynchronous before tick box on your script task.

Thanks a lot @Niall That clears up most of the things for me.

Just one more thing. I am executing scenarios wherein I have 3 different messages that could be thrown from the child. Is it good practice

  1. Add 3 message boundary events to the call activity?

or

  1. Register the messages before executing the call activity in parallel flow?

I am trying to achieve something like below. Is this achievable in any way?

They should be attached to the Call Activity to ensure that the messages are only expected while the child process is running.
Otherwise,if the message is not fired you could get a deadlock

Why do you not recommend using the process instance id when correlating?

I have currently an issue where I have a user task which has a boundary message event. When I try to send the corresponding message via the API to raise the message I also get the error:

Cannot correlate message 'XX': No process definition or execution matches the parameters

The request looks like the following:

{
  "messageName" : "rueckfrageGestellt",
  "processInstanceId": "66ff8fb6-7487-46bd-a5c8-73e39bedd1f6",
  "all" : false
}

Hey @adiii4,

so first of all your REST body looks totally fine. Can you provide more detail ( i.e your model ) ?
Your process instance needs to be in a waiting state for a message with the name “rueckfrageGestellt” and the processInstanceId needs to be matched/correlated.

Furthermore the Camunda Best Practices state:

" As a best practice, correlate incoming messages based on one unique artificial attribute (e.g. “correlationIdMyMessage”) created specifically for this communication. Alternatively you also have the option to select the process instance targeted by a message based on a query involving complex criteria and then as a second step explicitly correlate the message to the selected process instance."

The reason why the business key might be the better solution is that the processInstanceId is a very technical way to identify processes. Messages are used for 1 to 1 communications and therefore unique identifiers are needed.

Imagine an order fulfillment process with a leading ERP system communicating with camunda. The order number could be used as a business key to map orders from the ERP system with process instances. But as said before - querying for process instances is also one way of getting things done :wink:

Hey @Norman_Luering

Here is my model:

And here the current instances in the cockpit:

As mentioned the boundary message event has the message name rueckfrageGestellt the following send task Meldung über Rückfrage senden is a service task which sends an email.

Then I might have to consider providing the business key when starting the process :slight_smile: but I still don’t why the processInstanceId is enough, isn’t the id unique enough for correlating messages?

Hey @adiii4,

there has to be something going on wrong, because the processInstanceId is totally enough. Can you check for whitespaces and provide me the xml of your bpmn model? Also please check the processInstanceId is actually running and waiting at the UserTask “Antrag prüfen”.

Here is my example:

Calling http://localhost:8080/rest/message with this body:

{
"messageName":"msg_testinterruption",
"processInstanceId":"3f8121a9-5a1d-11ea-9141-74da38ef37c8",
"all":false
}

leads to a HTTP 204 and this:

Hope this will help you resolving your issue.

Cheers!
Norman

Hi @adiii4,

Why do you not recommend using the process instance id when correlating?

You should not use the processInstanceId to correlate a message as this is internal information of the framework and should not easily be exposed to the surrounding systems.

For example, when you have to delete and restart the receiveing process instance, the id, known to the caller, didn’t work anymore. But if you correlate with business data, it’s likely that the caller process instance will find the receiving process instance.

Hope this helps, Ingo

Hi @Ingo_Richtsmeier

This makes totally sense. Thank you for your explanation!

Thanks also to @Norman_Luering for finding the bug in my process model. The problem was that the message was not attached to user task even though it looked visually like it. So be sure that your message events are really boundary events, when you want them like this :smiley: