Correlate message for multi instance task

That’s because you are using correlate rather than correlateAll see the other methods and the java doc. Correlate only correlates to a single instance. You need to tell it to correlate to all matching instances

Yes, but I have 3 parallel executions, and get 3 callbacks for each execution. So I should correlate only one execution per callback.

@thedenische can you double confirm that the correlationId value in each of your sub-process instances are different values?

Yes, correlationId has three different values for each multi instance subprocess, and for any value I get this error, when correlating message.

Feels like a bug then… Can you remove the event gateway, and just have a parallel gateway, and see if it works? I know it wont be a functional process as the parallel will create two tokens (one on each catch event), but we just want to see if its the event gateway that is breaking things.

I replaced event based gateway with parallel gateway and still get the same error.

not near a computer to test, so just giving you troubleshooting questions for now:
If you remove the multi-instance, and just have a single sub-process, does it work? If yes, then same scenario but activate two entirely different instances of the parent process, and test against, does that work?

Okay found the issue. It is because a embedded sub process is a activity and not a different process. Best solution I found was to use a call activity. You can still save your process levels variables for the sub process that was started by the call activity. And you can continue to use the event gateway.

Thank you a lot.
Yes, I could switch to Call Activity as a workaround. But looks like it will be more suitable to use AbstractBpmnActivityBehavior or External Task

Your model is very close to a External task pattern. So if you can use that all the better.

1 Like

Hi @StephenOTT
Coming back to this example is it possible to get a list of local matches from a query?
So for the following array I’d expect to get back two instances, however this will return the four instances.

var array1 = ["dog","cat","horse","cat"]`

Something like the following, but actually works :slight_smile: ?

List<Execution> list = runtimeService
                .createExecutionQuery()
                .messageEventSubscriptionName("MyCustomMessage")
                .processVariableValueEquals("customMatchVariable", "cat")
                .list();

I couldn’t find an equivalent ‘processLocalVariableValueEquals’ for this example.

Any suggestions about how I could do this?

Can a message start event or catch event have local variables ?

Not sure what you mean but I’m using the original example you provided, to understand how to match against local variables in a query.

The correlation example you provided, is similar to what I need, but I only need to get back the process executions. I don’t want to correlate. The input did the trick, thanks.

Thus my question is, you have say four instances within the multiple-instance task ( e.g. “dog”,“cat”,“horse”,“cat”), how do I match against the local variable, say ‘cat’ and return only the matched instance(s).

So for example, How to find a multiInstanceBody Task with a specific variable value
The following returns a list of instances.

List<Execution> list = runtimeService
            .createExecutionQuery()
            .messageEventSubscriptionName("MyCustomMessage")
            .processVariableValueEquals("customMatchVariable", "cat")
            .list();

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