AnsweredAssumed Answered

Cannot accomplish a very simple correlation

Question asked by ejyanezp on Nov 12, 2014
Latest reply on Nov 19, 2014 by jbarrez
Hi, I am trying to make a simple correlation tutorial, it is very simple but i cannot make it work.

The process is as follows (only the semantic part):

<definitions … …>
  <message id="correlation" name="Correlation"></message>
  <process id="myProcessCorrelation" name="My process Correlation" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <scriptTask id="scripttask1" name="Print before" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>println "Before"</script>
    </scriptTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="scripttask1"></sequenceFlow>
    <intermediateCatchEvent id="messageintermediatecatchevent1" name="MessageCatchEvent">
      <messageEventDefinition messageRef="correlation"/>
    </intermediateCatchEvent>
    <sequenceFlow id="flow2" sourceRef="scripttask1" targetRef="messageintermediatecatchevent1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="messageintermediatecatchevent1" targetRef="scripttask2"></sequenceFlow>
    <scriptTask id="scripttask2" name="Print After" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>println "After"</script>
    </scriptTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow4" sourceRef="scripttask2" targetRef="endevent1"></sequenceFlow>
  </process>
</definitions>

And the JUnit code (only the segment that matters):

RuntimeService runtimeService = activitiRule.getRuntimeService();
Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("name", "Activiti");
      
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcessCorrelation", variableMap);
      
Execution execution = runtimeService.createExecutionQuery()
               .messageEventSubscriptionName("Correlation")
               .variableValueEquals("name", "Activiti")
               .singleResult();
      
runtimeService.messageEventReceived("Correlation", execution.getId());  // <– execution is null, why??!?!?!?

The problem is that null is assigned to the execution variable. I don't know why :S

You can download the eclipse project from this link

Any help?

Regards.
Eduardo Yánez.

Outcomes