cancel
Showing results for 
Search instead for 
Did you mean: 

Correlating an external message to an Execution

ktm
Champ in-the-making
Champ in-the-making
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
3 REPLIES 3

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
I don't understand how Executions are related to process instances,

Here is the answer

ktm
Champ in-the-making
Champ in-the-making
These 2 queries get me to the Execution I want:
      Execution processEx = runtimeService.createExecutionQuery()
              .processInstanceBusinessKey("abc")
              .singleResult();

      Execution messageListener = runtimeService.createExecutionQuery()
              .processInstanceId(processEx.getProcessInstanceId())
              .messageEventSubscriptionName("callbackMessage")
              .singleResult();

I was expecting the following to work, but it does not:
      Execution messageListener = runtimeService.createExecutionQuery()
              .processInstanceBusinessKey("abc")
              .messageEventSubscriptionName("callbackMessage")
              .singleResult();

It seems to me that there is a kind of parent/child relationship here and I feel as though an ExecutionQuery on business key should return all Executions which are associated with the ProcessInstance which was created with said business key.

I'm just complaining, when you get down to it.

jbarrez
Star Contributor
Star Contributor
Indeed, the executions are actually a tree of executions:

http://nurkiewicz.blogspot.be/2011/01/activiti-processes-and-executions.html
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.