Message Intermediate Catch Event - how to find the right instance?

Hi there,
I have got a process, which waits for a REST request from another system in a “Message Intermediate Catch Event”.
Here ist my process:


In the camunda modeler I can give a name to the message by clicking on the catch event and then fill out “Details”:
grafik

If I now start the process and fill out the form an the usertaks, the process waits at the message intermediate catch event for my message. I send the following via postman:

via: localhost:8080/engine-rest/message

{
  "messageName" : "FormChecked_OneLane_TwoUser",
  "processVariables" : {
    "permissionApproved" : {"value" : "approved", "type": "String" },
  }
}

The following flows (yes and no) check via a method if my REST call sends approved or denied,
grafik

grafik

That works great.
But I get a problem, if two or more instances wait at the message intermediate catch event
Screenshot from cockpit:
grafik

I get an “MismatchingMessageCorrelationException”:
…Cannot correlate a message with name ‘FormChecked_OneLane_TwoUser’ to a single execution. …

I understand it in the way, that I have to identify, for which processInstance the sended message is for.

But how can I do that? My external application could send the processInstance like this:

{
  "messageName" : "FormChecked_OneLane_TwoUser",
  "processVariables" : {
    "permissionApproved" : {"value" : "approved", "type": "String" },
    "processInstanceId" : {"value" : "e8dbdd8-92ef-11ec-8065-a434d96233af", "type": "String" }
  }
}

But how can I receive it? I tried it with setting the processinstance id in the input parameters via the modeler, but that does not work.
grafik

An example would be great. Thank you a lot,
Nicole

Hi @NickiMueller,

you have to use the correlationKeys to identify the process instance: Correlate a Message | docs.camunda.org

The processVariables are set to the process instance when the message is delivered.

Hope this helps, Ingo

Hi @Ingo_Richtsmeier ,

I tried now to set a business key at the start event of my process. Here is the screenshot that shows that it worked:

Then I used the following request:

But I get the following error:
org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate message 'FormChecked_OneLane_TwoUser': No process definition or execution matches the parameters"

What am I doing wrong?
Thank you a lot,
Nicole

I found a solution. At the start event of the process I set the processinstanceid as businesskey via a listener:

The processInstanceId is saved to my extern software. After doing some work in the extern software, it sends a request like this: (postman is only for testing)
grafik

I do not know if that is a good way, but it works. The only question for me would be, how I can prevent the dialog in tasklist, which asks for a business key.

Any ideas?
Thank you, Nicole

Hi @NickiMueller,

correlationKeys attribute refers to process variables not the process instance Id so it is incorrect to set process instance Id as a correlation key. If you do so then a process variable with the name “processInstanceId” which holds the same value as the one supplied should exist which is not the case.

In short, use either businessKey or processInstanceId but don’t pass process instance Id as if it were a process variable.

1 Like

Hi @NickiMueller,

You can add a blank form to the start event. It should have a formKey pointing to an embedded form with a html file containing something like:

<form>Enter your data in the next task</form> 

Hope this helps, Ingo

2 Likes