AnsweredAssumed Answered

Correlating an external message to an Execution

Question asked by ktm on Apr 12, 2013
Latest reply on Apr 15, 2013 by jbarrez
I have a simple process with an eventBasedGateway.  I have 2 intermediateCatchEvents after the gateway; one has a timer and the other has a messageEventDefinition ("userCallback").  I have a test; the test works.  However, it seems wrong.

In my test, I create a process instance:

      Map<String, Object> variables = new HashMap<String, Object>();
      variables.put("tempId", "ktm099");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("createUser", "bizKey", variables);

I query the Execution and apply the message, and this works.  But I think my query is wrong.  I expect to query for businessKey and messageEventSubscriptionName.  But this does not work.  I get null for my query.  This does work:

        Execution execution = runtimeService.createExecutionQuery()
         .messageEventSubscriptionName("callbackMessage")
         .processVariableValueEquals("tempId", "ktm099")
         .singleResult();

Digging into this, I find that the engine holds 2 executions.  The first has the businesKey but no messageEventSubscription.  The second has the messageEventSubscription but businessKey is null.

I don't understand how Executions are related to process instances, so I am writing to ask if there is a pattern for this kind of correlation.

Thanks.
Kit

Outcomes