dobedo
dobedo

Reputation: 135

Query process instances based on starting message name

ENV: camunda 7.4, BPMN 2.0

Given a process, which can be started by multiple start message events.

  1. is it possible to query process instances started by specific messages identified by message name?
  2. if yes, how?
  3. if no, why?
  4. if not at the moment, when?

Some APIs like IncidentMessages?

Upvotes: 0

Views: 507

Answers (1)

thorben
thorben

Reputation: 1587

That is no out-of-the-box feature but should be easy to build by using process variables.

The basic steps are:

1. Implement an execution listener that sets the message name as a variable:

public class MessageStartEventListener implements ExecutionListener {

  public void notify(DelegateExecution execution) throws Exception {
    execution.setVariable("startMessage", "MessageName");
  }
}

Note that via DelegateExecution#getBpmnModelElementInstance you can access the BPMN element that the listener is attached to, so you could determine the message name dynamically.

2. Declare the execution listener at the message start events:

<process id="executionListenersProcess">
  <startEvent id="theStart">
    <extensionElements>
      <camunda:executionListener
          event="start" class="org.camunda.bpm.examples.bpmn.executionlistener.MessageStartEventListener" />
    </extensionElements>
    <messageEventDefinition ... />
  </startEvent>

  ...
</process>

Note that with a BPMN parse listener, you can add such a listener programmatically to every message start event in every process definition. See this example.

3. Make a process instance query filtering by that variable

RuntimeService runtimeService = processEngine.getRuntimeService();
List<ProcessInstance> matchingInstances = runtimeService
  .createProcessInstanceQuery()
  .variableValueEquals("startMessage", "MessageName")
  .list();

Upvotes: 1

Related Questions