broker/tigger实践
创建broker br01
[root@master ~]# kn broker create br01
Broker 'br01' successfully created in namespace 'default'.
[root@master ~]# kn broker list
NAME URL AGE CONDITIONS READY REASON
br01 http://broker-ingress.knative-eventing.svc.cluster.local/default/br01 4s 6 OK / 6 True
创建trigger
[root@master ~]# kn trigger create tr01 --broker br01 --sink ksvc:event-display-01 --filter type=com.yang.sayhi
Trigger 'tr01' successfully created in namespace 'default'.
[root@master ~]# kubectl get trigger
NAME BROKER SUBSCRIBER_URI AGE READY REASON
tr01 br01 http://event-display-01.default.svc.cluster.local 110s True
[root@master ~]# kn trigger list
NAME BROKER SINK AGE CONDITIONS READY REASON
tr01 br01 ksvc:event-display-01 43s 6 OK / 6 True
[root@master ~]# kn trigger create tr02 --broker br01 --sink ksvc:event-display-02 --filter type=com.yang.saybye
Trigger 'tr02' successfully created in namespace 'default'.
[root@master ~]# kn trigger list
NAME BROKER SINK AGE CONDITIONS READY REASON
tr01 br01 ksvc:event-display-01 5m53s 6 OK / 6 True
tr02 br01 ksvc:event-display-02 21s 6 OK / 6 True
查看broker地址
[root@master ~]# kn broker list
NAME URL AGE CONDITIONS READY REASON
br01 http://broker-ingress.knative-eventing.svc.cluster.local/default/br01 11m 6 OK / 6 True
直接在集群内部pod进行curl,测试sayhi
curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/default/br01" -X POST -H "Content-Type: application/cloudevents+json" \
-d '{"id": "say-hi", "specversion": "1.0", "type": "com.yang.sayhi", "source": "sendoff", "data": {"msg":"Hello Knative default Broker Say HI"}}'
root@client-5592 # curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/default/br01" -X POST -H "Content-Type: application/cloude
vents+json" \
> -d '{"id": "say-hi", "specversion": "1.0", "type": "com.yang.sayhi", "source": "sendoff", "data": {"msg":"Hello Knative default Broker Say HI
"}}'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 10.103.81.173:80...
* TCP_NODELAY set
* Connected to broker-ingress.knative-eventing.svc.cluster.local (10.103.81.173) port 80 (#0)
> POST /default/br01 HTTP/1.1
> Host: broker-ingress.knative-eventing.svc.cluster.local
> User-Agent: curl/7.67.0
> Accept: */*
> Content-Type: application/cloudevents+json
> Content-Length: 140
>
* upload completely sent off: 140 out of 140 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 202 Accepted
< allow: POST, OPTIONS
< date: Fri, 21 Oct 2022 06:39:53 GMT
< content-length: 0
< x-envoy-upstream-service-time: 10
< server: envoy
<
* Connection #0 to host broker-ingress.knative-eventing.svc.cluster.local left intact
测试saybye
curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/default/br01" -X POST -H "Content-Type: application/cloudevents+json" \
-d '{"id": "say-bye", "specversion": "1.0", "type": "com.yang.saybye", "source": "sendoff", "data": {"msg":"Hello Knative default Broker Say BYE"}}'
root@client-5592 # curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/default/br01" -X POST -H "Content-Type: application/cloude
vents+json" \
> -d '{"id": "say-bye", "specversion": "1.0", "type": "com.yang.saybye", "source": "sendoff", "data": {"msg":"Hello Knative default Broker Say
BYE"}}'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 10.103.81.173:80...
* TCP_NODELAY set
* Connected to broker-ingress.knative-eventing.svc.cluster.local (10.103.81.173) port 80 (#0)
> POST /default/br01 HTTP/1.1
> Host: broker-ingress.knative-eventing.svc.cluster.local
> User-Agent: curl/7.67.0
> Accept: */*
> Content-Type: application/cloudevents+json
> Content-Length: 143
>
* upload completely sent off: 143 out of 143 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 202 Accepted
< allow: POST, OPTIONS
< date: Fri, 21 Oct 2022 06:41:22 GMT
< content-length: 0
< x-envoy-upstream-service-time: 9
< server: envoy
<
* Connection #0 to host broker-ingress.knative-eventing.svc.cluster.local left intact