Mutliple instance / correlation problem

Hello,

In my project, i use camunda with the following setup :

  • spring-boot : 2.3.0.RELEASE
  • camunda : 7.12.0
  • camunda-bpm-assert : 5.0.0

In my bpmn multiple_instance.bpmn (see above), a parallel multiple instance subprocess is used.
A collection is declared with an element variable (for mapping) - no loop cardinality is used.
I’m not able to correlate a message with an instance of this subprocess. The error thrown by camunda looks like :

ENGINE-13031 Cannot correlate a message with name ‘X’ to a single execution. Y executions match the correlation keys

Here are two reproducers. The collection (items) used by the multiple instance subprocess is given at a process instance creation. Then, we try to correlate with an item of the collection.

    @Test
    public void reproducer1() {

        List<String> items = Arrays.asList("item1", "item2", "items3");

        BpmnAwareTests
                .runtimeService()
                .createProcessInstanceByKey("multiplie_instance_problem")
                .businessKey("businessKey")
                .setVariable("items", items)
                .execute();


        Map<String, Object> correlationKeysMap = new HashMap<>();
        correlationKeysMap.put("item", "item1");

        BpmnAwareTests
                .runtimeService()
                .correlateMessage(
                        "message_for_subprocess",
                        "businessKey",
                        correlationKeysMap,
                        null);
    }

    @Test
    public void reproducer2() {
        List<String> items = Arrays.asList("item1", "item2", "items3");

        BpmnAwareTests
                .runtimeService()
                .createProcessInstanceByKey("multiplie_instance_problem")
                .businessKey("businessKey")
                .setVariable("items", items)
                .execute();

        BpmnAwareTests
                .runtimeService()
                .createMessageCorrelation("message_for_subprocess")
                .processInstanceBusinessKey("businessKey")
                .processInstanceVariableEquals("item", "item1")
                .correlate();
    }

Can you help me ?
I don’t understand if i’m doing something wrong or if it is a bug.
Thanks

multiple_instance.bpmn (6.1 KB)

Hi, Welcome to the Community.

Can you show me what code you’re using to actually trigger the message event? (i.e. how you’re sending the message) ?

In my project, camunda is embedded in a spring boot rest service.
“Production” code is quite similar than the code provided in my reproducers.

It looks like

@Service
public class CamundaService {

    private ProcessEngine processEngine;

    public void executeCorrelation(
            String eventMessage, String businessKey, String correlationKey, String correlationValue) {

        Map<String, Object> correlationKeys = new HashMap<>();
        correlationKeysMap.put(correlationKey, correlationValue);

        processEngine
                .getRuntimeService()
                .correlateMessage(
                        eventMessage,
                        businessKey,
                        correlationKeys ,
                        null
                );
    }

}

It seems that camunda ignores correlationKeys => if there are more than on subprocess instance, camunda throws the error i gave in my first message (it works if there is only one subprocess instance).

Thanks for your reply

You’re using an older method for sending messages.
Try something like this

       runtimeService.createMessageCorrelation("MessageName")
                .processInstanceBusinessKey("key")
                .localVariableEquals("item", "ItemValue")
                .correlate();

I’ve updated my junit as you proposed.
Unfortunately it still doesn’t work.

However, error is now different :

Cannot correlate message ‘message_for_subprocess’: No process definition or execution matches the parameters

@Test
    public void reproducer3() {
        List<String> items = Arrays.asList("item1", "item2", "items3");

        ProcessInstance processInstance = BpmnAwareTests
                .runtimeService()
                .createProcessInstanceByKey("multiplie_instance_problem")
                .businessKey("businessKey")
                .setVariableLocal("items", items)
                .execute();

        BpmnAwareTests
                .runtimeService()
                .createMessageCorrelation("message_for_subprocess")
                .processInstanceBusinessKey("businessKey")
                .localVariableEquals("item", "item1")
                .correlate();
    }

As expected, three subprocess instances are well created but a correlation with a specific instance cannot be achieved.

Can something be missing in bpmn ?

Can you run an assert to check to make sure that the engine is actually waiting for the message to come in?

Assert on the event id is true

        BpmnAwareTests
                .assertThat(processInstance)
                .isWaitingAt("event_for_subprocess");

If I set a bad value

        BpmnAwareTests
                .assertThat(processInstance)
                .isWaitingAt("bad_event_id");

error message is :

java.lang.AssertionError: Expecting ProcessInstance {id=‘9’, processDefinitionId=‘multiplie_instance_problem:2:7’, businessKey=‘businessKey’} to be waiting at [bad_event_id], but it is actually waiting at [event_for_subprocess, event_for_subprocess, event_for_subprocess].

As expected, we see that three instances are waiting to be correlated.

I’ve just noticed that you’re creating the list variable as “local” when you create the instance. It should be a regular variable.
The variables become local per instance of the list. not the list itself, so try that and see how it goes

Same error :frowning:

Cannot correlate message ‘message_for_subprocess’: No process definition or execution matches the parameters

    @Test
    public void reproducer3() {
        List<String> items = Arrays.asList("item1", "item2", "items3");

        ProcessInstance processInstance = BpmnAwareTests
                .runtimeService()
                .createProcessInstanceByKey("multiplie_instance_problem")
                .businessKey("businessKey")
                .setVariable("items", items)
                .execute();

        BpmnAwareTests
                .runtimeService()
                .createMessageCorrelation("message_for_subprocess")
                .processInstanceBusinessKey("businessKey")
                .localVariableEquals("item", "item1")
                .correlate();
    }

Here is a sample spring boot maven projet reproducing the problem : github project

A REST webservice with camunda embedded/h2 database is available.
Two junit classes (one doing REST calls, the other using BpmnAwareTests) are also available to reproduce the problem.

I don’t understand why i can’t correlate a specific subprocess instance.
The problem also exists with a sequential multiple instances subprocess.

It’s working with a “call activity” task.
Can someone explain why it doesn’t work with one bpmn file ?