6.5. 将工作流链接到事件系统


OpenShift Serverless Logic Operator 使用 Knative Eventing、SinkBinding 和 triggers 将工作流与事件系统相关联。这些对象由 OpenShift Serverless Logic Operator 自动创建,并简化工作流事件的生产和消耗。

以下示例显示了为使用平台范围事件系统配置的 example-workflow 工作流创建的 Knative Eventing 对象:

apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
  name: sonataflow-platform-example
  namespace: example-namespace
spec:
  eventing:
    broker:
      ref:
        name: example-broker 
1

        apiVersion: eventing.knative.dev/v1
        kind: Broker
  services:
    dataIndex: 
2

      enabled: true
    jobService: 
3

      enabled: true
  ...
Copy to Clipboard Toggle word wrap
1
example-broker 对象供 Data Index、Job Service 和 example-workflow 工作流使用。
2
Data Index 部署有临时配置。
3
Jobs 服务使用临时配置部署。

example-broker 对象是一个 Kafka 类代理,其配置在 kafka-broker-config 配置映射中定义。

以下示例演示了如何配置用于 SonataFlowPlatform 的 Kafka Knative Broker:

apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
  annotations:
    eventing.knative.dev/broker.class: Kafka 
1

  name: example-broker
  namespace: example-namespace
spec:
  config:
    apiVersion: v1
    kind: ConfigMap
    name: kafka-broker-config
    namespace: knative-eventing
Copy to Clipboard Toggle word wrap
1
Kafka 类用于创建 example-broker 对象。

以下示例显示 example-workflow 如何自动链接到 example-namespace 中的用于事件 production 和 consume 的 example-broker

apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
metadata:
  name: example-workflow
  namespace: example-namespace
  annotations:
    sonataflow.org/description: Example Workflow
    sonataflow.org/version: 0.0.1
    sonataflow.org/profile: preview
spec:
  flow:
    start: ExampleStartState
    events:
      - name: outEvent1
        source: ''
        kind: produced
        type: out-event-type1 
1

      - name: inEvent1
        source: ''
        kind: consumed
        type: in-event-type1 
2

      - name: inEvent2
        source: ''
        kind: consumed
        type: in-event-type2 
3

    states:
      - name: ExampleStartState
    ...
Copy to Clipboard Toggle word wrap
1
使用名为 example-workflow - sb 的 SinkBinding 生成 example-workflow 传出事件。
2
使用 example-workflow-inevent1-b40c067c-595b-4913-81a4-c8efa980bc11 触发器来消耗 in-event-type1 类型的事件。
3
使用 example-workflow-inevent2-b40c067c-595b-4913-81a4-c8efa980bc11 触发器来消耗 in-event-type2 类型的事件。

您可以使用以下命令列出自动创建的名为 example-workflow-sbSinkBinding

$ oc get sinkbindings -n example-namespace
Copy to Clipboard Toggle word wrap

输出示例

NAME                   TYPE          RESOURCE                           SINK                    READY
example-workflow-sb    SinkBinding   sinkbindings.sources.knative.dev   broker:example-broker   True
Copy to Clipboard Toggle word wrap

您可以使用以下命令列出为事件消耗自动创建的触发器:

$ oc get triggers -n <example-namespace>
Copy to Clipboard Toggle word wrap

输出示例

NAME                                                              BROKER           SINK                                                     AGE   CONDITIONS   READY   REASON
example-workflow-inevent1-b40c067c-595b-4913-81a4-c8efa980bc11    example-broker   service:example-workflow                                 16m   7 OK / 7     True
example-workflow-inevent2-b40c067c-595b-4913-81a4-c8efa980bc11    example-broker   service:example-workflow                                 16m   7 OK / 7     True
Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat