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

Knative Eventing Parallel Flow 示例

时间:2023-11-20 12:23:49浏览次数:33  
标签:even 示例 Eventing demo Flow dev knative odd parallel

环境说明

◼  PingSource负责生成event
◼ Parallel中有两个Branch
  ◆ 第一个分支接受时间为偶数的事件
  ◆ 第二个分支接受时间为奇数的事件
◼ 所有分支的最终结果均发往ksvc/event-display,内容格式化Cloud Event存储入日志

创建名称空间

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

创建 Filter

transformers.yaml

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: even-filter
  namespace: parallel-demo
spec:
  template:
    spec:
      containers:
      - image: villardl/filter-nodejs:0.1
        env:
        - name: FILTER
          value: |
            Math.round(Date.parse(event.time) / 60000) % 2 === 0
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: odd-filter
  namespace: parallel-demo
spec:
  template:
    spec:
      containers:
      - image: villardl/filter-nodejs:0.1
        env:
        - name: FILTER
          value: |
            Math.round(Date.parse(event.time) / 60000) % 2 !== 0
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: even-transformer
  namespace: parallel-demo
spec:
  template:
    spec:
      containers:
      - image: villardl/transformer-nodejs
        env:
        - name: TRANSFORMER
          value: |
            ({"message": "we are even!"})

---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: odd-transformer
  namespace: parallel-demo
spec:
  template:
    spec:
      containers:
      - image: villardl/transformer-nodejs:0.1
        env:
        - name: TRANSFORMER
          value: |
            ({"message": "this is odd!"})

创建 Filter 资源

# kubectl apply -f transformers.yaml
service.serving.knative.dev/even-filter created
service.serving.knative.dev/odd-filter created
service.serving.knative.dev/even-transformer created
service.serving.knative.dev/odd-transformer created

查看 Filter ksvc

# kubectl get ksvc -n parallel-demo
NAME               URL                                                   LATESTCREATED            LATESTREADY              READY   REASON
even-filter        http://even-filter.parallel-demo.svc.wgs.local        even-filter-00001        even-filter-00001        True    
even-transformer   http://even-transformer.parallel-demo.svc.wgs.local   even-transformer-00001   even-transformer-00001   True    
odd-filter         http://odd-filter.parallel-demo.svc.wgs.local         odd-filter-00001         odd-filter-00001         True    
odd-transformer    http://odd-transformer.parallel-demo.svc.wgs.local    odd-transformer-00001    odd-transformer-00001    True    

创建 event-display

event-display.yaml

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: event-display
  namespace: parallel-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 parallel-demo
NAME               URL                                                   LATESTCREATED            LATESTREADY              READY   REASON
even-filter        http://even-filter.parallel-demo.svc.wgs.local        even-filter-00001        even-filter-00001        True    
even-transformer   http://even-transformer.parallel-demo.svc.wgs.local   even-transformer-00001   even-transformer-00001   True    
event-display      http://event-display.parallel-demo.svc.wgs.local      event-display-00001      event-display-00001      True    
odd-filter         http://odd-filter.parallel-demo.svc.wgs.local         odd-filter-00001         odd-filter-00001         True    
odd-transformer    http://odd-transformer.parallel-demo.svc.wgs.local    odd-transformer-00001    odd-transformer-00001    True    

创建 Parallel

parallel.yaml

apiVersion: flows.knative.dev/v1
kind: Parallel
metadata:
  name: odd-even-parallel
  namespace: parallel-demo
spec:
  channelTemplate:
    apiVersion: messaging.knative.dev/v1
    kind: InMemoryChannel
  branches:
    - filter:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: even-filter
          namespace: parallel-demo
      subscriber:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: even-transformer
          namespace: parallel-demo
    - filter:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: odd-filter
          namespace: parallel-demo
      subscriber:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: odd-transformer
          namespace: parallel-demo
  reply:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: event-display
      namespace: parallel-demo

创建 parallel 资源

# kubectl apply -f parallel.yaml
parallel.flows.knative.dev/odd-even-parallel created

查看 parallel 资源

# kubectl get parallel -n parallel-demo
NAME                URL                                                                           AGE   READY   REASON
odd-even-parallel   http://odd-even-parallel-kn-parallel-kn-channel.parallel-demo.svc.wgs.local   70s   True    

创建 PingSource

ping-source.yaml

apiVersion: sources.knative.dev/v1
kind: PingSource
metadata:
  name: ping-source
  namespace: parallel-demo
spec:
  schedule: "*/1 * * * *"
  contentType: "application/json"
  data: '{"message": "Even or odd?"}'
  sink:
    ref:
      apiVersion: flows.knative.dev/v1
      kind: Parallel
      name: odd-even-parallel
      namespace: parallel-demo

创建 pingsource 资源

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

查看 pingsource 资源

# kubectl get pingsource -n parallel-demo
NAME          SINK                                                                          SCHEDULE      AGE   READY   REASON
ping-source   http://odd-even-parallel-kn-parallel-kn-channel.parallel-demo.svc.wgs.local   */1 * * * *   13s   True    

验证结果

查看 pod

# kubectl get pod -n parallel-demo
NAME                                                 READY   STATUS    RESTARTS   AGE
event-display-00001-deployment-68f569cbc6-6ff8h      2/2     Running   0          5m47s

查看日志

# kubectl logs event-display-00001-deployment-68f569cbc6-6ff8h -c user-container -n parallel-demo
☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: dev.knative.sources.ping
  source: /apis/v1/namespaces/parallel-demo/pingsources/ping-source
  id: 5ed746c7-5919-4d23-8512-817ce0e6675d
  time: 2023-11-20T03:52:00.078441452Z
  datacontenttype: application/json; charset=utf-8
Data,
  {
    "message": "we are even!"
  }
☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: dev.knative.sources.ping
  source: /apis/v1/namespaces/parallel-demo/pingsources/ping-source
  id: ecbc2852-2d80-4ffc-9ce4-ad1ae07c98b3
  time: 2023-11-20T03:53:00.343279246Z
  datacontenttype: application/json; charset=utf-8
Data,
  {
    "message": "this is odd!"
  }
☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: dev.knative.sources.ping
  source: /apis/v1/namespaces/parallel-demo/pingsources/ping-source
  id: 7e5dbcde-6687-4f9f-aa2e-15446a655ec3
  time: 2023-11-20T03:54:00.034946307Z
  datacontenttype: application/json; charset=utf-8
Data,
  {
    "message": "we are even!"
  }
☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: dev.knative.sources.ping
  source: /apis/v1/namespaces/parallel-demo/pingsources/ping-source
  id: 52fb84bb-bdcc-4c18-ab5b-a485d8be7459
  time: 2023-11-20T03:55:00.034468672Z
  datacontenttype: application/json; charset=utf-8
Data,
  {
    "message": "this is odd!"
  }

参考文档

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

https://github.com/knative/docs/blob/main/code-samples/eventing/parallel/multiple-branches/README.md

标签:even,示例,Eventing,demo,Flow,dev,knative,odd,parallel
From: https://www.cnblogs.com/wangguishe/p/17842778.html

相关文章

  • springboot 控制序列化反序列化示例(接口返回数据处理/接口接收数据处理)
    1.返回Long转JSONpackagecom.mingx.drone.config;importcom.fasterxml.jackson.core.JsonGenerator;importcom.fasterxml.jackson.databind.JsonSerializer;importcom.fasterxml.jackson.databind.SerializerProvider;importjava.io.IOException;/***@Descript......
  • Knative Eventing Sequence Flow 示例
    环境说明◼PingSource负责生成event◼Event由Sequence中的各Step顺次处理◆各Step都运行一个appender应用◆分别向收到的数据尾部附加自定义的专有数据项◼最终结果发往ksvc/event-display环境示意图创建名称空间#kubectlcreatenssequence-demonamespace/seq......
  • 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......