Camunda中的错误处理

797 阅读2分钟

DZone>开放源代码区 > Camunda的错误处理

Camunda中的错误处理

看看如何在Camunda中用错误捕获事件来捕获异常。

Prashanth Boorla user avatar通过

邓小平

·

Aug. 06, 21 -开源区 -教程

喜欢 (2)

评论

保存

Tweet

2.63K浏览次数

加入DZone社区,获得完整的会员体验。

免费加入

在本教程中,我们将学习如何在Camunda中处理异常。对于这一点

使用此链接创建一个带有嵌入式Camunda引擎的Spring Boot项目。使用7.15.0版本。

其他要求

  • Spring Boot 2.4.3
  • Camunda 7.15.0
  • Eclipse或任何其他IDE

在Camunda中处理异常

将Maven项目导入Eclipse,并添加所需的依赖项。

  1. 在Camunda建模器中创建服务任务并为该服务任务添加错误捕获事件。
  2. 每当服务任务发生异常时,错误捕捉事件就会捕捉到该异常,并将该服务任务抛入相应的旅程流。
  3. 如果你没有给出任何错误捕捉事件,它将在驾驶舱中被创建为一个事件,并且令牌将被回滚到开始事件。

使用Camunda modeler保存以下XML内容,扩展名为.bpmn,以获得具有错误捕获事件的流程模型。

爪哇

<?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:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_12zbd5u" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.5.0">
  <bpmn:collaboration id="Collaboration_1vtn4s6">
    <bpmn:participant id="Participant_18yien5" name="Error Handling" processRef="Process_1jtu8ae" />
  </bpmn:collaboration>
  <bpmn:process id="Process_1jtu8ae" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_0vs3b46</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:endEvent id="Event_08wul9s">
      <bpmn:incoming>Flow_0kby2yc</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_0vs3b46" sourceRef="StartEvent_1" targetRef="Activity_0snk7cd" />
    <bpmn:sequenceFlow id="Flow_0kby2yc" sourceRef="Activity_0snk7cd" targetRef="Event_08wul9s" />
    <bpmn:serviceTask id="Activity_0snk7cd" name="Service Task" camunda:delegateExpression="${ServiceTaskDelegate}">
      <bpmn:incoming>Flow_0vs3b46</bpmn:incoming>
      <bpmn:outgoing>Flow_0kby2yc</bpmn:outgoing>
    </bpmn:serviceTask>
    <bpmn:sequenceFlow id="Flow_0qbi7m4" sourceRef="Event_01bk0vq" targetRef="Event_0my2aab" />
    <bpmn:boundaryEvent id="Event_01bk0vq" attachedToRef="Activity_0snk7cd">
      <bpmn:outgoing>Flow_0qbi7m4</bpmn:outgoing>
      <bpmn:errorEventDefinition id="ErrorEventDefinition_1eepl13" errorRef="Error_00fdfpv" camunda:errorCodeVariable="code_variable" />
    </bpmn:boundaryEvent>
    <bpmn:endEvent id="Event_0my2aab">
      <bpmn:incoming>Flow_0qbi7m4</bpmn:incoming>
      <bpmn:errorEventDefinition id="ErrorEventDefinition_1hkclb7" errorRef="Error_00fdfpv" />
    </bpmn:endEvent>
  </bpmn:process>
  <bpmn:error id="Error_00fdfpv" name="BPMN_ERROR" errorCode="error_code" />
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1vtn4s6">
      <bpmndi:BPMNShape id="Participant_18yien5_di" bpmnElement="Participant_18yien5" isHorizontal="true">
        <dc:Bounds x="129" y="52" width="600" height="316" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="Flow_0qbi7m4_di" bpmnElement="Flow_0qbi7m4">
        <di:waypoint x="390" y="228" />
        <di:waypoint x="390" y="290" />
        <di:waypoint x="462" y="290" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0kby2yc_di" bpmnElement="Flow_0kby2yc">
        <di:waypoint x="440" y="170" />
        <di:waypoint x="512" y="170" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0vs3b46_di" bpmnElement="Flow_0vs3b46">
        <di:waypoint x="278" y="170" />
        <di:waypoint x="340" y="170" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="242" y="152" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_08wul9s_di" bpmnElement="Event_08wul9s">
        <dc:Bounds x="512" y="152" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0h53qgw_di" bpmnElement="Activity_0snk7cd">
        <dc:Bounds x="340" y="130" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_1vjkbhx_di" bpmnElement="Event_0my2aab">
        <dc:Bounds x="462" y="272" width="36" height="36" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_18eo0oc_di" bpmnElement="Event_01bk0vq">
        <dc:Bounds x="372" y="192" width="36" height="36" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

在Camunda modeler中复制粘贴上述XML文件后,你可以看到下图。

将下面的片段添加到异常处理中

使用主类文件运行应用程序,观察输出结果,其中异常被错误捕获事件捕获并通过错误抛出事件传递。

主题。

camunda bpm, camunda, 教程

DZone贡献者所表达的观点属于他们自己。

DZone上的热门话题


评论

开源 合作伙伴资源