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?


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="" xmlns:bpmndi="" xmlns:dc="" xmlns:camunda="" xmlns:xsi="" xmlns:di="" id="Definitions_0ipjg8y" targetNamespace="" exporter="Camunda Modeler" exporterVersion="4.0.0">
  <bpmn:process id="Process_1cge2cd" isExecutable="true">
    <bpmn:subProcess id="Activity_1dyp5mb">
      <bpmn:startEvent id="Event_10rzt15">
      <bpmn:serviceTask id="Activity_13hv1a2" name="Send notify" camunda:expression="#{activation.sendNotify(execution)}">
      <bpmn:intermediateCatchEvent id="Event_0hgychx" name="Response">
        <bpmn:messageEventDefinition id="MessageEventDefinition_1kabwyk" messageRef="Message_0tsftsh" />
      <bpmn:intermediateCatchEvent id="Event_1xf8hiv">
        <bpmn:timerEventDefinition id="TimerEventDefinition_0t4v320">
          <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT30S</bpmn:timeDuration>
      <bpmn:sendTask id="Activity_13ebga9" name="Throw message request canceled" camunda:expression="#{activation.throwMessageRequestCanceled(execution)}">
      <bpmn:eventBasedGateway id="Gateway_17jbkw3">
      <bpmn:endEvent id="Event_0mivnqj" name="End process">
      <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:endEvent id="Event_1hx2osv" name="End process">
      <bpmn:sequenceFlow id="Flow_0k7b56n" sourceRef="Activity_0c8bbcq" targetRef="Event_1hx2osv" />
    <bpmn:startEvent id="Event_0t6fur0" name="Activation received">
      <bpmn:messageEventDefinition id="MessageEventDefinition_0kvi0iq" messageRef="Message_0drtufv" />
    <bpmn:sequenceFlow id="Flow_016awm2" sourceRef="Event_0t6fur0" targetRef="Activity_1dyp5mb" />
    <bpmn:boundaryEvent id="Event_05nv0rm" name="Cancel request" attachedToRef="Activity_1dyp5mb">
      <bpmn:errorEventDefinition id="ErrorEventDefinition_1pm9gjx" errorRef="Error_0c46dxm" />
    <bpmn:boundaryEvent id="Event_1guf6nq" name="Parking request canceled" attachedToRef="Activity_1dyp5mb">
      <bpmn:messageEventDefinition id="MessageEventDefinition_1j4rrbb" messageRef="Message_0ijnxbs" />
    <bpmn:serviceTask id="Activity_1q6qvra" name="Send notification of cancellation" camunda:expression="#{activation.sendCancelRequestNotification(execution)}">
    <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:sequenceFlow id="Flow_1yhpjpy" sourceRef="Activity_1q6qvra" targetRef="Event_15vhv5c" />
  <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 id="Flow_0cu7zvl_di" bpmnElement="Flow_0cu7zvl">
        <di:waypoint x="730" y="348" />
        <di:waypoint x="730" y="400" />
      <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 id="Flow_016awm2_di" bpmnElement="Flow_016awm2">
        <di:waypoint x="218" y="180" />
        <di:waypoint x="250" y="180" />
      <bpmndi:BPMNShape id="Activity_1dyp5mb_di" bpmnElement="Activity_1dyp5mb" isExpanded="true">
        <dc:Bounds x="250" y="80" width="620" height="250" />
      <bpmndi:BPMNEdge id="Flow_0k7b56n_di" bpmnElement="Flow_0k7b56n">
        <di:waypoint x="730" y="180" />
        <di:waypoint x="782" y="180" />
      <bpmndi:BPMNEdge id="Flow_0yplyig_di" bpmnElement="Flow_0yplyig">
        <di:waypoint x="598" y="180" />
        <di:waypoint x="630" y="180" />
      <bpmndi:BPMNEdge id="Flow_1sxjmv5_di" bpmnElement="Flow_1sxjmv5">
        <di:waypoint x="326" y="180" />
        <di:waypoint x="360" y="180" />
      <bpmndi:BPMNEdge id="Flow_01qp4yx_di" bpmnElement="Flow_01qp4yx">
        <di:waypoint x="730" y="270" />
        <di:waypoint x="762" y="270" />
      <bpmndi:BPMNEdge id="Flow_03488b4_di" bpmnElement="Flow_03488b4">
        <di:waypoint x="598" y="270" />
        <di:waypoint x="630" y="270" />
      <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 id="Flow_1owfpbv_di" bpmnElement="Flow_1owfpbv">
        <di:waypoint x="545" y="180" />
        <di:waypoint x="562" y="180" />
      <bpmndi:BPMNEdge id="Flow_1ymg84j_di" bpmnElement="Flow_1ymg84j">
        <di:waypoint x="460" y="180" />
        <di:waypoint x="495" y="180" />
      <bpmndi:BPMNShape id="Event_10rzt15_di" bpmnElement="Event_10rzt15">
        <dc:Bounds x="290" y="162" width="36" height="36" />
      <bpmndi:BPMNShape id="Activity_13hv1a2_di" bpmnElement="Activity_13hv1a2">
        <dc:Bounds x="360" y="140" width="100" height="80" />
      <bpmndi:BPMNShape id="Event_0hgychx_di" bpmnElement="Event_0hgychx">
        <dc:Bounds x="562" y="162" width="36" height="36" />
          <dc:Bounds x="555" y="205" width="51" height="14" />
      <bpmndi:BPMNShape id="Event_1xf8hiv_di" bpmnElement="Event_1xf8hiv">
        <dc:Bounds x="562" y="252" width="36" height="36" />
      <bpmndi:BPMNShape id="Activity_13ebga9_di" bpmnElement="Activity_13ebga9">
        <dc:Bounds x="630" y="230" width="100" height="80" />
      <bpmndi:BPMNShape id="Gateway_17jbkw3_di" bpmnElement="Gateway_17jbkw3">
        <dc:Bounds x="495" y="155" width="50" height="50" />
      <bpmndi:BPMNShape id="Event_0mivnqj_di" bpmnElement="Event_0mivnqj">
        <dc:Bounds x="762" y="252" width="36" height="36" />
          <dc:Bounds x="749" y="295" width="62" height="14" />
      <bpmndi:BPMNShape id="Activity_09ezne0_di" bpmnElement="Activity_0c8bbcq">
        <dc:Bounds x="630" y="140" width="100" height="80" />
      <bpmndi:BPMNShape id="Event_1hx2osv_di" bpmnElement="Event_1hx2osv">
        <dc:Bounds x="782" y="162" width="36" height="36" />
          <dc:Bounds x="769" y="205" width="62" height="14" />
      <bpmndi:BPMNShape id="Event_0t6fur0_di" bpmnElement="Event_0t6fur0">
        <dc:Bounds x="182" y="162" width="36" height="36" />
          <dc:Bounds x="177" y="205" width="48" height="27" />
      <bpmndi:BPMNShape id="Activity_1q6qvra_di" bpmnElement="Activity_1q6qvra">
        <dc:Bounds x="680" y="400" width="100" height="80" />
      <bpmndi:BPMNShape id="Event_15vhv5c_di" bpmnElement="Event_15vhv5c">
        <dc:Bounds x="842" y="422" width="36" height="36" />
      <bpmndi:BPMNShape id="Event_1guf6nq_di" bpmnElement="Event_1guf6nq">
        <dc:Bounds x="712" y="312" width="36" height="36" />
          <dc:Bounds x="741" y="356" width="78" height="27" />
      <bpmndi:BPMNShape id="Event_05nv0rm_di" bpmnElement="Event_05nv0rm">
        <dc:Bounds x="642" y="312" width="36" height="36" />
          <dc:Bounds x="582" y="353" width="75" height="14" />

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


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.