准备两个Filter
kn service create image-filter --image villardl/filter-nodejs:0.1 --env FILTER='event.type == "com.yang.file.image"' --scale-min=1
kn service create text-filter --image villardl/filter-nodejs:0.1 --env FILTER='event.type == "com.yang.file.text"' --scale-min=1
准备两个Subscriber
kn service create para-appender-image --image ikubernetes/appender --env MESSAGE=" - filetype/Image" --scale-min=1
kn service create para-appender-text --image ikubernetes/appender --env MESSAGE=" - filetype/Text" --scale-min=1
创建并查看parallel资源
[root@master parallel-demo]# kubectl apply -f 05-parallel.yaml
[root@master parallel-demo]# cat 05-parallel.yaml
---
apiVersion: flows.knative.dev/v1
kind: Parallel
metadata:
name: filetype-parallel
namespace: default
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
branches:
- filter:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: image-filter
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: para-appender-image
- filter:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: text-filter
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: para-appender-text
reply:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display-01
[root@master parallel-demo]# kubectl get parallel
NAME URL AGE READY REASON
filetype-parallel http://filetype-parallel-kn-parallel-kn-channel.default.svc.cluster.local 71s True
curl -v "http://filetype-parallel-kn-parallel-kn-channel.default.svc.cluster.local" -X POST -H "Content-Type: application/cloudevents+json" \
-d '{"id": "say-bye", "specversion": "1.0", "type": "com.yang.file.image", "source": "sendoff", "data": {"message":"Hello Knative Parallel Flow Image"}}'
curl -v "http://filetype-parallel-kn-parallel-kn-channel.default.svc.cluster.local" -X POST -H "Content-Type: application/cloudevents+json" \
-d '{"id": "say-bye", "specversion": "1.0", "type": "com.yang.file.text", "source": "sendoff", "data": {"message":"Hello Knative Parallel Flow Text"}}'
[root@master ~]# kubectl logs event-display-01-00001-deployment-68d48cbdf8-lv9m4