Camunda event-based gateway

Hi all,

I have a event-based gateway with a timer and a message event attached, but I notice that even if I send the message event and therefore it should continue the flow on the message, the timer event still starts after the preset time.But the gateway does not work so that the first event that check stops other events?

Does the first event occurred interrupt other events?Or does the the timer-event lives for the all duration of the transaction?

Thanks

Yes - thats how the gateway is intended to work. It’s an exclusive OR gateway. If only one thread is active on the process instance no more than one event will ever happen.

Thanks for the quick reply, but then I don’t understand why when I send the message to the gateway at some point the timer also starts … do you know something?

I’m not exactly sure what you mean - can you upload your model and detail the steps that are taken by the process and what you expect to happen?

This is the xml:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0ipjg8y" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0">
  <bpmn:process id="Process_1cge2cd" isExecutable="true">
    <bpmn:subProcess id="Activity_1dyp5mb">
      <bpmn:incoming>Flow_016awm2</bpmn:incoming>
      <bpmn:startEvent id="Event_10rzt15">
        <bpmn:outgoing>Flow_1sxjmv5</bpmn:outgoing>
      </bpmn:startEvent>
      <bpmn:serviceTask id="Activity_13hv1a2" name="Send notify" camunda:expression="#{activation.sendNotify(execution)}">
        <bpmn:incoming>Flow_1sxjmv5</bpmn:incoming>
        <bpmn:outgoing>Flow_1ymg84j</bpmn:outgoing>
      </bpmn:serviceTask>
      <bpmn:intermediateCatchEvent id="Event_0hgychx" name="Response">
        <bpmn:incoming>Flow_1owfpbv</bpmn:incoming>
        <bpmn:outgoing>Flow_0yplyig</bpmn:outgoing>
        <bpmn:messageEventDefinition id="MessageEventDefinition_1kabwyk" messageRef="Message_0tsftsh" />
      </bpmn:intermediateCatchEvent>
      <bpmn:intermediateCatchEvent id="Event_1xf8hiv">
        <bpmn:incoming>Flow_1kdk1ay</bpmn:incoming>
        <bpmn:outgoing>Flow_03488b4</bpmn:outgoing>
        <bpmn:timerEventDefinition id="TimerEventDefinition_0t4v320">
          <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT30S</bpmn:timeDuration>
        </bpmn:timerEventDefinition>
      </bpmn:intermediateCatchEvent>
      <bpmn:sendTask id="Activity_13ebga9" name="Throw message request canceled" camunda:expression="#{activation.throwMessageRequestCanceled(execution)}">
        <bpmn:incoming>Flow_03488b4</bpmn:incoming>
        <bpmn:outgoing>Flow_01qp4yx</bpmn:outgoing>
      </bpmn:sendTask>
      <bpmn:eventBasedGateway id="Gateway_17jbkw3">
        <bpmn:incoming>Flow_1ymg84j</bpmn:incoming>
        <bpmn:outgoing>Flow_1owfpbv</bpmn:outgoing>
        <bpmn:outgoing>Flow_1kdk1ay</bpmn:outgoing>
      </bpmn:eventBasedGateway>
      <bpmn:endEvent id="Event_0mivnqj" name="End process">
        <bpmn:incoming>Flow_01qp4yx</bpmn:incoming>
      </bpmn:endEvent>
      <bpmn:sequenceFlow id="Flow_1ymg84j" sourceRef="Activity_13hv1a2" targetRef="Gateway_17jbkw3" />
      <bpmn:sequenceFlow id="Flow_1owfpbv" sourceRef="Gateway_17jbkw3" targetRef="Event_0hgychx" />
      <bpmn:sequenceFlow id="Flow_1kdk1ay" sourceRef="Gateway_17jbkw3" targetRef="Event_1xf8hiv" />
      <bpmn:sequenceFlow id="Flow_03488b4" sourceRef="Event_1xf8hiv" targetRef="Activity_13ebga9" />
      <bpmn:sequenceFlow id="Flow_01qp4yx" sourceRef="Activity_13ebga9" targetRef="Event_0mivnqj" />
      <bpmn:sequenceFlow id="Flow_1sxjmv5" sourceRef="Event_10rzt15" targetRef="Activity_13hv1a2" />
      <bpmn:sequenceFlow id="Flow_0yplyig" sourceRef="Event_0hgychx" targetRef="Activity_0c8bbcq" />
      <bpmn:serviceTask id="Activity_0c8bbcq" name="Check response" camunda:expression="#{activation.checkResponse(execution)}">
        <bpmn:incoming>Flow_0yplyig</bpmn:incoming>
        <bpmn:outgoing>Flow_0k7b56n</bpmn:outgoing>
      </bpmn:serviceTask>
      <bpmn:endEvent id="Event_1hx2osv" name="End process">
        <bpmn:incoming>Flow_0k7b56n</bpmn:incoming>
      </bpmn:endEvent>
      <bpmn:sequenceFlow id="Flow_0k7b56n" sourceRef="Activity_0c8bbcq" targetRef="Event_1hx2osv" />
    </bpmn:subProcess>
    <bpmn:startEvent id="Event_0t6fur0" name="Activation received">
      <bpmn:outgoing>Flow_016awm2</bpmn:outgoing>
      <bpmn:messageEventDefinition id="MessageEventDefinition_0kvi0iq" messageRef="Message_0drtufv" />
    </bpmn:startEvent>
    <bpmn:sequenceFlow id="Flow_016awm2" sourceRef="Event_0t6fur0" targetRef="Activity_1dyp5mb" />
    <bpmn:boundaryEvent id="Event_05nv0rm" name="Cancel request" attachedToRef="Activity_1dyp5mb">
      <bpmn:outgoing>Flow_1parz53</bpmn:outgoing>
      <bpmn:errorEventDefinition id="ErrorEventDefinition_1pm9gjx" errorRef="Error_0c46dxm" />
    </bpmn:boundaryEvent>
    <bpmn:boundaryEvent id="Event_1guf6nq" name="Parking request canceled" attachedToRef="Activity_1dyp5mb">
      <bpmn:outgoing>Flow_0cu7zvl</bpmn:outgoing>
      <bpmn:messageEventDefinition id="MessageEventDefinition_1j4rrbb" messageRef="Message_0ijnxbs" />
    </bpmn:boundaryEvent>
    <bpmn:serviceTask id="Activity_1q6qvra" name="Send notification of cancellation" camunda:expression="#{activation.sendCancelRequestNotification(execution)}">
      <bpmn:incoming>Flow_1parz53</bpmn:incoming>
      <bpmn:incoming>Flow_0cu7zvl</bpmn:incoming>
      <bpmn:outgoing>Flow_1yhpjpy</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_1parz53" sourceRef="Event_05nv0rm" targetRef="Activity_1q6qvra" />
    <bpmn:sequenceFlow id="Flow_0cu7zvl" sourceRef="Event_1guf6nq" targetRef="Activity_1q6qvra" />
    <bpmn:endEvent id="Event_15vhv5c">
      <bpmn:incoming>Flow_1yhpjpy</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1yhpjpy" sourceRef="Activity_1q6qvra" targetRef="Event_15vhv5c" />
  </bpmn:process>
  <bpmn:message id="Message_1xxq3lz" name="ParkingResponse" />
  <bpmn:message id="Message_0tsftsh" name="ParkingResponse" />
  <bpmn:message id="Message_0drtufv" name="parkingActivation" />
  <bpmn:error id="Error_0c46dxm" name="CancelRequestNotification" errorCode="com.telepass.service.tlpk1parkingorchestrator.exceptions.CancelRequestException" />
  <bpmn:message id="Message_0ijnxbs" name="RequestCanceled" />
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1cge2cd">
      <bpmndi:BPMNEdge id="Flow_1yhpjpy_di" bpmnElement="Flow_1yhpjpy">
        <di:waypoint x="780" y="440" />
        <di:waypoint x="842" y="440" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0cu7zvl_di" bpmnElement="Flow_0cu7zvl">
        <di:waypoint x="730" y="348" />
        <di:waypoint x="730" y="400" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1parz53_di" bpmnElement="Flow_1parz53">
        <di:waypoint x="660" y="348" />
        <di:waypoint x="660" y="440" />
        <di:waypoint x="680" y="440" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_016awm2_di" bpmnElement="Flow_016awm2">
        <di:waypoint x="218" y="180" />
        <di:waypoint x="250" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Activity_1dyp5mb_di" bpmnElement="Activity_1dyp5mb" isExpanded="true">
        <dc:Bounds x="250" y="80" width="620" height="250" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_0k7b56n_di" bpmnElement="Flow_0k7b56n">
        <di:waypoint x="730" y="180" />
        <di:waypoint x="782" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0yplyig_di" bpmnElement="Flow_0yplyig">
        <di:waypoint x="598" y="180" />
        <di:waypoint x="630" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1sxjmv5_di" bpmnElement="Flow_1sxjmv5">
        <di:waypoint x="326" y="180" />
        <di:waypoint x="360" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_01qp4yx_di" bpmnElement="Flow_01qp4yx">
        <di:waypoint x="730" y="270" />
        <di:waypoint x="762" y="270" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_03488b4_di" bpmnElement="Flow_03488b4">
        <di:waypoint x="598" y="270" />
        <di:waypoint x="630" y="270" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1kdk1ay_di" bpmnElement="Flow_1kdk1ay">
        <di:waypoint x="520" y="205" />
        <di:waypoint x="520" y="270" />
        <di:waypoint x="562" y="270" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1owfpbv_di" bpmnElement="Flow_1owfpbv">
        <di:waypoint x="545" y="180" />
        <di:waypoint x="562" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1ymg84j_di" bpmnElement="Flow_1ymg84j">
        <di:waypoint x="460" y="180" />
        <di:waypoint x="495" y="180" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="Event_10rzt15_di" bpmnElement="Event_10rzt15">
        <dc:Bounds x="290" y="162" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_13hv1a2_di" bpmnElement="Activity_13hv1a2">
        <dc:Bounds x="360" y="140" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0hgychx_di" bpmnElement="Event_0hgychx">
        <dc:Bounds x="562" y="162" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="555" y="205" width="51" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1xf8hiv_di" bpmnElement="Event_1xf8hiv">
        <dc:Bounds x="562" y="252" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_13ebga9_di" bpmnElement="Activity_13ebga9">
        <dc:Bounds x="630" y="230" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_17jbkw3_di" bpmnElement="Gateway_17jbkw3">
        <dc:Bounds x="495" y="155" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0mivnqj_di" bpmnElement="Event_0mivnqj">
        <dc:Bounds x="762" y="252" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="749" y="295" width="62" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_09ezne0_di" bpmnElement="Activity_0c8bbcq">
        <dc:Bounds x="630" y="140" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1hx2osv_di" bpmnElement="Event_1hx2osv">
        <dc:Bounds x="782" y="162" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="769" y="205" width="62" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_0t6fur0_di" bpmnElement="Event_0t6fur0">
        <dc:Bounds x="182" y="162" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="177" y="205" width="48" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_1q6qvra_di" bpmnElement="Activity_1q6qvra">
        <dc:Bounds x="680" y="400" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_15vhv5c_di" bpmnElement="Event_15vhv5c">
        <dc:Bounds x="842" y="422" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1guf6nq_di" bpmnElement="Event_1guf6nq">
        <dc:Bounds x="712" y="312" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="741" y="356" width="78" height="27" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_05nv0rm_di" bpmnElement="Event_05nv0rm">
        <dc:Bounds x="642" y="312" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="582" y="353" width="75" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

I expect that if I send the message “ParkingResponse” the flow continues where the message-event is and stop the timer. Instead it happens that the flow continues on the message event but does not stop the timer. In fact in debug mode on java if I stay still on “Check response” service task for some time, suddenly the timer starts too. Instead I expected the timer to be deleted … Thanks

The timer will be canceled after the message has reached a wait state.
Even if the timer is still running and has expired - it should not be picked up until while a thread is active on process instance.

And why in my case the timer event attached isn’t disabled?Why is it fired after 30 seconds also if the execution flow go in the direction of the message event?Thanks

Hard to know - can you create a failing testcase for me to look at?

You could also probably fix it by putting an ``Asynchronous After" marker on the message event.

1 Like

Yes, in fact, I also noticed this morning that in this way I solve the problem, but I just don’t understand why the original method doesn’t work for me …
However I will opt for the asynchronous mode … thanks for the help :slight_smile:

If i don’t put “Asynchronous After” the timer event always stays active until the end of the process. I don’t understand if it’s my mistake or something else of the event based gateway

Hi,

This is the expected behaviour, its the way the engine manages process state. For an event based gateway with a timer, there is a timer job in the database and say a message based event. If the message arrives, the process will execute in the context of the thread which delivers the message until a wait state is reached. A wait state can be the end of the process, a process element marked as async or an intrinsic wait state such as user task or receive event. On reaching a wait state, the engine will flush the process state to the database, which in this case would remove the timer job.

Hence, with async after the message event, the process state is flushed immediately and thus the timer job is cancelled. Without the async after the message event, the execution thread could continue processing for longer than the timer. In this case, the job executor will initiate the timer path. So now there is a race condition with two threads running concurrent but different process execution paths. One will win which causes the other to throw an optimistic locking exception. Hence the engine will return to a consistent process state, however side effects along the way may remain.

regards

Rob

2 Likes