Finding executions waiting for messages based on process variable matches


I’ve tried to get intermediate message catch events working. I’m trying to trigger the correct execution based on some correlation key I have.

The documentation on messages states that this query should work:

Execution execution = runtimeService.createExecutionQuery()
      .variableValueEquals("orderId", message.getOrderId())

However, I find that this query does always result in an empty set. I added a workaround in my code which does two queries, one for the Process Instance where I do the correlation, and another one for the execution where I use the PI as a parent along the message name.

Am I missing something or is this expected behaviour?

The query look ok at first glance. When are you setting the orderId variable? Are you sure the state is persisted already when doing this query?

An alternative is to use the RuntimeService#createEventSubscriptionQuery method (finding the event subscriptions and then getting the execution).

Another alternative to look into can be the eventing that was added in the 6.5.0 release. They have correlation parameter built in. See for more information.