Correlate message for multi instance task

I hate to dig up old questions, but im struggling with this issue, as i have a similar example, but instead of event gateway i want to correlate with message to interrupt a task within multi-instance subprocess (but only a single instance of task should be cancelled)


subParallelInterrupt.bpmn (6.1 KB)

now when i try to correlate message via rest api to a single instance with variable it can’t find instance (i know i can correlate it with a ton of code by capturing the message and finding instance manually but that’s not the way i want it)

{
"type": "RestException",
"message": "org.camunda.bpm.engine.MismatchingMessageCorrelationException: Cannot correlate 
  message 'STOP': No process definition or execution matches the parameters"
 }

messageBody:

{
  "messageName" : "STOP",
  "businessKey" : "1",
  "localCorrelationKeys" : {
    "assignee" : {"value" : "Rohan", "type": "String"}
  }
}

is there some way i can correlate it via rest api, without exporting my embedded sub-process to another process?

Hi @JohnArray,

I’ve digged deeper into your process model to understand what’s going on in the engine.

In your process model, you left some listeners and input mappings from further tryouts. I deleted them and got the same result.

Inspecting the database I saw that the events are connected to the user tasks, but the assignee variable is only on the subprocess level. So, the message correlation could not find the instances with this correlation keys.

If you put an input mapping to the user task like Name: assignee and Value ${assignee} your message correlation runs successfully.

To clarify the variable mapping, you can use another name like local_assignee and use this as local correlation key.

This processes subParallelInterrupt.bpmn (5.9 KB)

can accept this request:

POST engine-rest/message
{"messageName": "STOP", "localCorrelationKeys": {"local_assignee": {"value": "Chandra", "type": "String"}}}

Hope this helps, Ingo

1 Like

Yet another late addition to this topic :slight_smile:
I ran into a similar problem as @thedenische but used another solution.
In the following process I want to correlate a message for only a single sub-process instance at a time, based on an identifier variable in the sub-process scope:


forum_example.bpmn (9.2 KB)

My solution for that has been an execution listener script that sets the variable locally to the execution of the event-based gateway:

execution.setVariableLocal(‘ID’, ID);

My question: Is there any better way, or is this the recommended solution? I have looked at the recommendations provided to solve this problem but do not think they really fit my use case.

I also do not really understand why it is only possible to correlate on variables in the local or process instance scope (or why embedded sub-processes are not a whole new process instance, but an activity). This also leads to problems with standalone intermediate catch events in sub-processes, where I use input mapping to have the identifier in the local scope. A behaviour similar to getVariable, where the first occurence of the variable in the execution tree would be used to correlate a message, would help out a lot and make these workarounds obsolete.
Is this an intentional limitation?

Hi @LT_bmiag,

the BPMN specification says that messages have a 1-1 relationship between sender and receipient. A message send must be received by only a message receive event or -task.

If you create multiple message events with a multi instance subprocess, you have to identify each receiving message event. This is only possible with unique local variables.

Hope this helps, Ingo

Hi @thedenische

How you were able to resolve the issue? I am also facing the similar issue. Can you write down some piece of code. Actually I am new to Camunda.

Thanks
Pawan Pandey

How can you execute the same request in java? Is there an api that I can use. Currently for sending message events I am using the following:
ProcessEngines.getDefaultProcessEngine().getRuntimeService()
.createMessageCorrelation(messageName)
.processInstanceId(processInstanceId)
.correlate();
But don’t know how to add the localCorrelationKeys