zeebe入门课程13-YAML格式工作流说明1

版权声明:本文为博主原创文章,未经博主允许不得转载。不经过允许copy,讲追究法律责任,欢迎加入我们的学习提升群523988350,可以相互交流 https://blog.csdn.net/qq_30739519/article/details/89575593

除了BPMN之外,Zeebe还提供了一种用于定义工作流的yaml格式。创建yaml工作流可以使用常规文本编辑器完成,不需要图形建模工具。它受到命令式编程概念的启发,旨在让程序员容易理解。在内部,Zeebe将部署的yaml文件转换为bpmn。

name: order-process

tasks:
    - id: collect-money
      type: payment-service

    - id: fetch-items
      type: inventory-service

    - id: ship-parcel
      type: shipment-service

目前zeebe支持在如下三个类型的节点上进行使用。

Tasks

工作流可以包含多个任务,每个任务表示工作流中的一个步骤。

name: order-process

tasks:
    - id: collect-money
      type: payment-service

    - id: fetch-items
      type: inventory-service
      retries: 5

    - id: ship-parcel
      type: shipment-service
      headers:
            method: "express"
            withInsurance: false

每个任务都具有以下属性:

  • id (required): 任务的唯一标识符。
  • type (required): 定时器可以订阅的名称。
  • retries: 失败时,作业重试的次数。(默认值=3)
  • headers: 一个元数据列表,以键值对的形式出现,定时器可以访问这些元数据。

当Zeebe执行任务时,它会创建一个交给定时器的作业。定时器可以执行业务逻辑并最终完成作业以触发工作流中的继续。

Control Flow

控制流是关于执行任务的顺序。yaml格式提供了工具来决定何时执行哪个任务。

Sequences

在一个序列中,任务在前一个任务完成后执行。默认情况下,任务在yaml文件中声明时自上而下执行。

name: order-process

tasks:
    - id: collect-money
      type: payment-service

    - id: fetch-items
      type: inventory-service

    - id: ship-parcel
      type: shipment-service

在上面的示例中,工作流从“收款”开始,然后是“提取项目”,最后是“发货包裹”。

我们可以使用goto和end属性定义不同的顺序:

name: order-process

tasks:
    - id: collect-money
      type: payment-service
      goto: ship-parcel

    - id: fetch-items
      type: inventory-service
      end: true

    - id: ship-parcel
      type: shipment-service
      goto: fetch-items

在上面的例子中,我们已经颠倒了取件和发运包裹的顺序。请注意,需要结束属性,以便在获取项后停止工作流执行。

Data-based Conditions

有些工作流并不总是执行相同的任务,但需要根据工作流实例的变量选择不同的任务。

我们可以使用开关属性和条件来决定下一个任务。

name: order-process

tasks:
    - id: collect-money
      type: payment-service

    - id: fetch-items
      type: inventory-service
      switch:
          - case: totalPrice > 100
            goto: ship-parcel-with-insurance

          - default: ship-parcel

    - id: ship-parcel-with-insurance
      type: shipment-service-premium
      end: true

    - id: ship-parcel
      type: shipment-service

在上面的例子中,订单处理从收款开始,然后是获取项目。如果可变总价大于100,则继续进行带保险的邮包运输。否则,选择发货包裹。在这两种情况下,工作流实例都将在此之后结束。

在switch元素中,每个选项都有一个case元素可供选择。如果所有条件的计算结果都不为true,则计算默认元素。虽然不需要默认值,但最好在工作流运行时包括以避免错误。如果发生这样的错误(即没有满足任何情况,也没有默认值),则工作流执行将停止,并引发事件。

Data Flow

Zeebe以变量的形式将自定义数据从一个任务传送到另一个任务。变量是键值对,是工作流实例的一部分。

默认情况下,所有作业变量都合并到工作流实例中。可以通过在任务中定义输出映射来定制此行为。输入映射可用于将变量转换为定时器接受的格式。

name: order-process

tasks:
    - id: collect-money
      type: payment-service
      inputs:
          - source: totalPrice
            target: price
      outputs:
          - source: success
            target: paymentSuccess

    - id: fetch-items
      type: inventory-service

    - id: ship-parcel
      type: shipment-service

每个映射元素都有一个源元素和一个目标元素,该元素必须是变量表达式。

zeebe qq交流群群号:856546010

猜你喜欢

转载自blog.csdn.net/qq_30739519/article/details/89575593