首页 > 其他分享 >Knative Eventing Sequence Flow 示例

Knative Eventing Sequence Flow 示例

时间:2023-11-19 21:56:47浏览次数:25  
标签:sequence Eventing demo 示例 Flow dev display knative event

环境说明

◼ PingSource负责生成event
◼ Event由Sequence中的各Step顺次处理
  ◆各Step都运行一个appender应用
  ◆分别向收到的数据尾部附加自定义的专有数据项
◼ 最终结果发往ksvc/event-display

环境示意图

创建名称空间

# kubectl create ns sequence-demo
namespace/sequence-demo created

创建 step

steps.yaml

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: first
  namespace: sequence-demo
spec:
  template:
    spec:
      containers:
        - image: gcr.dockerproxy.com/knative-releases/knative.dev/eventing/cmd/appender
          env:
            - name: MESSAGE
              value: " - Handled by 0"

---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: second
  namespace: sequence-demo
spec:
  template:
    spec:
      containers:
        - image: gcr.dockerproxy.com/knative-releases/knative.dev/eventing/cmd/appender
          env:
            - name: MESSAGE
              value: " - Handled by 1"
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: third
  namespace: sequence-demo
spec:
  template:
    spec:
      containers:
        - image: gcr.dockerproxy.com/knative-releases/knative.dev/eventing/cmd/appender
          env:
            - name: MESSAGE
              value: " - Handled by 2"

创建 steps 资源

# kubectl apply -f steps.yaml
service.serving.knative.dev/first created
service.serving.knative.dev/second created
service.serving.knative.dev/third created

查看 steps 资源

# kubectl get ksvc -n sequence-demo
NAME     URL                                         LATESTCREATED   LATESTREADY    READY   REASON
first    http://first.sequence-demo.svc.wgs.local    first-00001     first-00001    True    
second   http://second.sequence-demo.svc.wgs.local   second-00001    second-00001   True    
third    http://third.sequence-demo.svc.wgs.local    third-00001     third-00001    True  

创建 event-display

event-display.yaml

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: event-display
  namespace: sequence-demo
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/min-scale: "1"
    spec:
      containers:
        - image: gcr.dockerproxy.com/knative-releases/knative.dev/eventing/cmd/event_display

创建 event-display 资源

# kubectl apply -f event-display.yaml
service.serving.knative.dev/event-display created

查看 event-display 资源

# kubectl get ksvc -n sequence-demo
NAME            URL                                                LATESTCREATED         LATESTREADY           READY   REASON
event-display   http://event-display.sequence-demo.svc.wgs.local   event-display-00001   event-display-00001   True    
first           http://first.sequence-demo.svc.wgs.local           first-00001           first-00001           True    
second          http://second.sequence-demo.svc.wgs.local          second-00001          second-00001          True    
third           http://third.sequence-demo.svc.wgs.local           third-00001           third-00001           True  

创建 sequence

sequence.yaml

apiVersion: flows.knative.dev/v1
kind: Sequence
metadata:
  name: sequence
  namespace: sequence-demo
spec:
  channelTemplate:
    apiVersion: messaging.knative.dev/v1
    kind: InMemoryChannel
  steps:
    - ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: first
        namespace: sequence-demo
    - ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: second
        namespace: sequence-demo
    - ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: third
        namespace: sequence-demo
  reply:
    ref:
      kind: Service
      apiVersion: serving.knative.dev/v1
      name: event-display
      namespace: sequence-demo

创建 sequence 资源

# kubectl apply -f sequence.yaml
sequence.flows.knative.dev/sequence created

查看 sequence 资源

# kubectl get sequences -n sequence-demo
NAME       URL                                                                    AGE   READY   REASON
sequence   http://sequence-kn-sequence-0-kn-channel.sequence-demo.svc.wgs.local   69s   True    

创建 PingSource

ping-source.yaml

apiVersion: sources.knative.dev/v1
kind: PingSource
metadata:
  name: ping-source
  namespace: sequence-demo
spec:
  schedule: "*/2 * * * *"
  contentType: "application/json"
  data: '{"message": "Hello world!"}'
  sink:
    ref:
      apiVersion: flows.knative.dev/v1
      kind: Sequence
      name: sequence
      namespace: sequence-demo

创建 pingsource 资源

# kubectl apply -f ping-source.yaml
pingsource.sources.knative.dev/ping-source created

查看 pingsource 资源

# kubectl get PingSource -n sequence-demo
NAME          SINK                                                                   SCHEDULE      AGE   READY   REASON
ping-source   http://sequence-kn-sequence-0-kn-channel.sequence-demo.svc.wgs.local   */2 * * * *   64s   True    

验证结果

查看 pod

# kubectl get pod -n sequence-demo
NAME                                              READY   STATUS    RESTARTS   AGE
event-display-00002-deployment-5d884ddd6f-qhwpx   2/2     Running   0          32s

查看日志

# kubectl logs event-display-00002-deployment-5d884ddd6f-qhwpx  -c user-container -n sequence-demo
☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: dev.knative.sources.ping
  source: /apis/v1/namespaces/sequence-demo/pingsources/ping-source
  id: 8df28a0b-2391-405b-a369-28c23882e6af
  time: 2023-11-19T13:44:00.245632902Z
  datacontenttype: application/json
Data,
  {
    "id": 0,
    "message": "Hello world! - Handled by 0 - Handled by 1 - Handled by 2"
  }

参考文档

https://knative.dev/docs/eventing/flows/sequence/

标签:sequence,Eventing,demo,示例,Flow,dev,display,knative,event
From: https://www.cnblogs.com/wangguishe/p/17836908.html

相关文章

  • lazy-flow(4)
    网关流转的幂等性问题。举个例子:一个简单的网关,满足条件走A线,不满足走B线。已知,走A的候选人和走B的候选人不一样,候选人都涉及多位,需要当前审核人自行选一个。假设审核人基于当前网关判断走A,所以从A的相关候选人中选了一个。但提交完成的处理过程中,网关的判定结果发生了变化,也即......
  • 通过PowerShellPlus示例脚本学习PowerShell-连接SQLServer数据库
    ##=====================================================================##Title:Connect-MSSQL-IPSQLAuth##Description:Connectto$ServerNameusingSQLServerauthentication.##Thisconnectionisnotencrypted.##......
  • Tcpdump使用示例
    这里收集了一些实用的tcpdump使用示例,使用它们可提升您的网络故障排除和安全测试能力。熟练掌握下面的tcpdump使用示例,可以帮助我们更好的了解自己的网络。了解tcpdump是一项基本技能,不仅对于系统管理员、网络工程师或安全专业人员,对于自己部署玩的一些服务器来说,也会派上......
  • Halo2简单示例
    Halo2简介[[Halo2]]是使用[[Rust]]语言开发,基于[[PLANK算法]]的,一款开源交互式([[STARKs]]),[[零知识证明(ZKP)]]的[[证明系统]]。GitHub仓库地址:halo2不同于普通的开发框架,Halo2中的功能开发称为电路(Circuit)开发,电路开发使用表格来设计并记录运算,并包含一系列的约束来验证......
  • 通过PowershellPlus示例脚本学习PowerShell-CheckDB
    ##=====================================================================##Title:CheckDB-MSSQL-UsingADO##Description:RunaDBCCagainstspecifiedserverinstanceanddatabase##Author:Idera##Date:9/1/2008##Input:-......
  • netcore 间隔时长修改参数 示例
    usingSystem;usingSystem.Threading.Tasks;classProgram{privatestaticintyourParameter=0;staticasyncTaskMain(){while(true){//等待5分钟awaitTask.Delay(TimeSpan.FromMinutes(5));//在这......
  • Mutiny Uni阻塞操作变响应式的方法示例
    以下代码片段为模拟一个这样的操作:在多台服务器上下载文件列表内的文件。其中,获取服务器、获取文件列表、在服务器执行下载操作均为阻塞方法。importcn.hutool.core.collection.CollUtil;importio.quarkus.test.junit.QuarkusTest;importio.smallrye.mutiny.Multi;impor......
  • TensorFlow tfrecord的解析
    importtensorflowastfimportjsonaa={"label":{"binary_label":{"is_use":1,"data_type":"int64","default_value":0,"feature_le......
  • SQL(Structured Query Language)简介和常见 SQL 命令示例
    简介SQL(StructuredQueryLanguage)是一种用于访问和操作关系型数据库的标准语言。它是一个功能强大的语言,用于执行各种数据库操作,包括检索数据、插入新记录、更新记录、删除记录、创建数据库、创建新表、设置权限以及执行存储过程和视图等。以下是SQL的一些重要方面:SQL的目的......
  • 深度学习笔记:搭建基于Python的tensorflow运行环境1
    使用python3命令创建tensorflow虚拟运行环境首先,在系统下创建python虚拟环境目录Venvs,本文我们设置的虚拟环境目录如下:C:\Users\wuchh\venvs,接下来打开cmd命令窗口进入创建的目录(C:\Users\wuchh\venvs)。在命令行窗口中,执行创建虚拟环境的python3命令,我们将创建一个名为......