zeebe快速体验

本文,Zeebe教程将帮助您了解Zeebe的主要概念,而无需编写一行代码。

  • 下载Zeebe发行版
  • 启动Zeebe容器
  • 部署工作流
  • 创建工作流实例
  • 完成工作流实例
  • 下一步

注意:如果使用cmd或powershell,某些命令示例可能无法在Windows上工作。对于Windows用户,我们建议使用类似于bash的shell,即git bash、cygwin或mingw。

步骤1:下载Zeebe发行版

您可以从Zeebe发行版页面下载最新发行版。网速慢的话,也可以进入qq交流群:856546010 进行下载。解压并输入要存放zeebe的目录。

tar -xzvf zeebe-distribution-X.Y.Z.tar.gz
cd zeebe-broker-X.Y.Z/

zeebe快速体验

步骤2:启动Zeebe容器

要启动Zeebe容器,请使用进入bin/文件夹中的broker或broker.bat文件。

./bin/broker
13:14:41.297 [] [main] INFO  io.zeebe.util.config - Reading configuration for class class io.zeebe.broker.system.configuration.BrokerCfg from file /home/philipp/zeebe/zeebe-broker-0.17.0/conf/zeebe.cfg.toml
13:14:41.415 [] [main] INFO  io.zeebe.broker.system - Scheduler configuration: Threads{cpu-bound: 2, io-bound: 2}.
13:14:41.445 [] [main] INFO  io.zeebe.broker.system - Version: 0.17.0
13:14:41.450 [] [main] INFO  io.zeebe.broker.system - Starting broker with configuration {
  "network": {
    "host": "0.0.0.0",
    "defaultSendBufferSize": "16M",
    "portOffset": 0,
    "client": {
      "controlMessageBufferSize": "8M",
      "host": "0.0.0.0",
      "port": 26501,
      "sendBufferSize": "16M"
    },
    "management": {
      "receiveBufferSize": "8M",
      "host": "0.0.0.0",
      "port": 26502,
      "sendBufferSize": "16M"
    },
    "replication": {
      "host": "0.0.0.0",
      "port": 26503,
      "sendBufferSize": "16M"
    },
    "subscription": {
      "receiveBufferSize": "8M",
      "host": "0.0.0.0",
      "port": 26504,
      "sendBufferSize": "16M"
    }
  },
  "cluster": {
    "initialContactPoints": [],
    "partitionIds": [
      0
    ],
    "nodeId": 0,
    "partitionsCount": 1,
    "replicationFactor": 1,
    "clusterSize": 1
  },
  "threads": {
    "cpuThreadCount": 2,
    "ioThreadCount": 2
  },
  "metrics": {
    "reportingInterval": "5s",
    "file": "/home/philipp/zeebe/zeebe-broker-0.17.0/metrics/zeebe.prom",
    "enableHttpServer": false,
    "host": "0.0.0.0",
    "port": 9600
  },
  "data": {
    "directories": [
      "/home/philipp/zeebe/zeebe-broker-0.17.0/data"
    ],
    "defaultLogSegmentSize": "512M",
    "snapshotPeriod": "15m",
    "snapshotReplicationPeriod": "5m"
  },
  "gossip": {
    "retransmissionMultiplier": 3,
    "probeInterval": "1s",
    "probeTimeout": "500ms",
    "probeIndirectNodes": 3,
    "probeIndirectTimeout": "1s",
    "suspicionMultiplier": 5,
    "syncTimeout": "3s",
    "syncInterval": "15s",
    "joinTimeout": "1s",
    "joinInterval": "1s",
    "leaveTimeout": "1s",
    "maxMembershipEventsPerMessage": 32,
    "maxCustomEventsPerMessage": 8
  },
  "raft": {
    "heartbeatInterval": "250ms",
    "electionInterval": "1s",
    "leaveTimeout": "1s"
  },
  "exporters": [],
  "gateway": {
    "enable": true,
    "network": {
      "host": "0.0.0.0",
      "port": 26500
    },
    "cluster": {
      "contactPoint": "0.0.0.0:26501",
      "transportBuffer": "128M",
      "requestTimeout": "15s"
    },
    "threads": {
      "managementThreads": 1
    }
  }
}
13:14:41.529 [] [main] INFO  io.zeebe.gateway - Version: 0.17.0
13:14:41.530 [] [main] INFO  io.zeebe.gateway - Starting gateway with configuration {
  "enable": true,
  "network": {
    "host": "0.0.0.0",
    "port": 26500
  },
  "cluster": {
    "contactPoint": "0.0.0.0:26501",
    "transportBuffer": "128M",
    "requestTimeout": "15s"
  },
  "threads": {
    "managementThreads": 1
  }
}
13:14:41.537 [service-controller] [0.0.0.0:26501-zb-actors-0] INFO  io.zeebe.broker.transport - Bound subscriptionApi.server to /0.0.0.0:26504
13:14:41.539 [service-controller] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.broker.transport - Bound managementApi.server to /0.0.0.0:26502
13:14:41.604 [service-controller] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26502' on transport 'managementApi.client'
13:14:41.607 [service-controller] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26504' on transport 'subscriptionApi.client'
13:14:41.607 [service-controller] [0.0.0.0:26501-zb-actors-0] INFO  io.zeebe.transport - Bound clientApi.server to /0.0.0.0:26501
13:14:41.610 [service-controller] [0.0.0.0:26501-zb-actors-0] INFO  io.zeebe.transport - Bound replicationApi.server to /0.0.0.0:26503
13:14:41.630 [] [main] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '-1' with address '0.0.0.0:26501' on transport 'broker-client'
13:14:41.630 [] [main] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '-1' with address '0.0.0.0:26501' on transport 'broker-client-internal'
13:14:41.738 [topology] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26502' on transport 'managementApi.client'
13:14:41.738 [topology] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26503' on transport 'replicationApi.client'
13:14:41.739 [topology] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26504' on transport 'subscriptionApi.client'
13:14:41.765 [io.zeebe.gateway.impl.broker.cluster.BrokerTopologyManagerImpl] [gateway-zb-actors-0] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26501' on transport 'broker-client'
13:14:41.766 [io.zeebe.gateway.impl.broker.cluster.BrokerTopologyManagerImpl] [gateway-zb-actors-0] INFO  io.zeebe.transport.endpoint - Registering endpoint for node '0' with address '0.0.0.0:26501' on transport 'broker-client-internal'
13:14:42.032 [service-controller] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.raft - Created raft partition-0 with configuration RaftConfiguration{heartbeatInterval='250ms', electionInterval='1s', leaveTimeout='1s'}
13:14:42.222 [partition-0] [0.0.0.0:26501-zb-actors-0] INFO  io.zeebe.raft - Joined raft in term 0
13:14:42.280 [zb-stream-processor] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.logstreams - Recovering state of partition 0 from snapshot
13:14:42.851 [zb-stream-processor] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.logstreams - Recovered state of partition 0 from snapshot at position -1
13:14:43.002 [zb-stream-processor] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.processor - Start scanning the log for error events.
13:14:43.003 [zb-stream-processor] [0.0.0.0:26501-zb-actors-1] INFO  io.zeebe.processor - Finished scanning the log for error events.

您将看到一些包容器版本和配置参数的输出。

要继续此指南,请打开另一个终端以使用zeebe cli zbctl执行命令。

我们现在可以检查Zeebe容器的状态。

./bin/zbctl status
Cluster size: 1
Partitions count: 1
Replication factor: 1
Brokers:
  Broker 0 - 0.0.0.0:26501
    Partition 0 : Leader

步骤3:部署工作流

在本指南中,我们将使用示例process order-process.bpmn。

zeebe快速体验

 

这个流程描述了三个任务的连续流程:收集钱、取货和运送包裹。如果您在文本编辑器中打开order-process.bpmn文件,您将看到每个任务都有一个在XML中定义的属性类型,该类型稍后将用作作业类型。

<!-- [...] -->
<bpmn:serviceTask id="collect-money" name="Collect Money">
  <bpmn:extensionElements>
    <zeebe:taskDefinition type="payment-service" />
  </bpmn:extensionElements>
</bpmn:serviceTask>
<!-- [...] -->
<bpmn:serviceTask id="fetch-items" name="Fetch Items">
  <bpmn:extensionElements>
    <zeebe:taskDefinition type="inventory-service" />
  </bpmn:extensionElements>
</bpmn:serviceTask>
<!-- [...] -->
<bpmn:serviceTask id="ship-parcel" name="Ship Parcel">
  <bpmn:extensionElements>
    <zeebe:taskDefinition type="shipment-service" />
  </bpmn:extensionElements>
</bpmn:serviceTask>
<!-- [...] -->

要完成此工作流的一个实例,我们需要为每种类型的支付服务、库存服务和发货服务激活并完成一个作业。

但首先让我们将工作流部署到Zeebe broker。

./bin/zbctl deploy order-process.bpmn
{
  "key": 2,
  "workflows": [
    {
      "bpmnProcessId": "order-process",
      "version": 1,
      "workflowKey": 1,
      "resourceName": "order-process.bpmn"
    }
  ]
}

步骤4:创建工作流实例

部署工作流之后,我们可以创建新的工作流实例。工作流的每个实例都是工作流的单个执行。要创建新实例,我们必须从bpmn文件中指定流程ID,在我们的示例中,ID是order-process.bpmn中定义的订单流程:

<bpmn:process id="order-process" isExecutable="true">

工作流的每个实例通常处理某种数据。我们可以在启动实例时将实例的初始数据指定为变量。

注意:要使用cmd或powershell执行此命令的Windows用户必须以不同的方式转义变量。

命令:“\”orderid\“:1234”

PowerShell:“”“orderID”“\”:1234”

./bin/zbctl create instance order-process --variables '{"orderId": 1234}'
{
  "workflowKey": 1,
  "bpmnProcessId": "order-process",
  "version": 1,
  "workflowInstanceKey": 3
}

步骤5:完成工作流实例

要完成实例,必须执行所有三个任务。在Zeebe中,会为工作流实例执行期间到达的每个任务创建一个作业。为了完成一项工作,从而完成相应的任务,必须由工作人员激活和完成。作业工人是一个长期存在的过程,它反复尝试激活给定作业类型的作业,并在执行其业务逻辑后完成这些作业。zbctl还提供一个命令,使用外部命令或脚本生成简单的作业工人。作业工人将在stdin上以json对象的形式接收每个作业的工作流实例变量,如果成功处理作业,则必须在stdout上以json对象的形式返回其结果。

在这个例子中,我们使用unix命令cat,它只输出它在stdin上接收到的内容。要完成工作流实例,我们现在必须为工作流定义中的三种任务类型(支付服务、库存服务和发货服务)中的每一种创建一个工作人员。

注意:对于Windows用户,此命令不与cmd一起使用,因为cat命令不存在。我们建议使用PowerShell或类似bash的shell来执行此命令

./bin/zbctl create worker payment-service --handler cat &
./bin/zbctl create worker inventory-service --handler cat &
./bin/zbctl create worker shipment-service --handler cat &
2019/04/02 13:23:01 Activated job 9 with variables {"orderId":1234}
2019/04/02 13:23:01 Handler completed job 9 with variables {"orderId":1234}

2019/04/02 13:23:01 Activated job 16 with variables {"orderId":1234}
2019/04/02 13:23:01 Handler completed job 16 with variables {"orderId":1234}

2019/04/02 13:23:01 Activated job 23 with variables {"orderId":1234}
2019/04/02 13:23:01 Handler completed job 23 with variables {"orderId":1234}

当工作人员在后台运行之后,我们可以创建更多的工作流实例,以观察工作人员将如何完成它们。

./bin/zbctl create instance order-process --variables '{"orderId": 12345}'

要关闭所有作业,请使用kill命令停止后台进程。

kill %1 %2 %3

如果要可视化工作流实例的状态,可以启动Zeebe简单监视器。

下一步

要继续使用Zeebe,我们建议您更熟悉Zeebe的基本概念,请参阅文档的“基础”一章。

在bpmn工作流一章中,您可以找到有关使用bpmn创建工作流的介绍。而bpmn建模器一章向您展示了如何自己建模它们。

文档还提供了使用JAVA或GO实现工作人员的入门指南。

zeebe qq交流群群号:856546010

 

 

 

 

上一篇:What is Zeebe?


下一篇:新版本Unity Import Assets时没有系统资源包