第 11 章 将功能订阅到 CloudEvents
您可以将功能订阅到一组事件。这会将您的功能链接到您的过滤器定义的 CloudEvent
对象,并启用自动响应。
11.1. 将功能订阅到 CloudEvents
subscribe
命令将功能连接到一组事件,与 CloudEvent
元数据的一系列过滤器以及 Knative Broker 作为被消耗的事件源匹配。
先决条件
- 在集群中安装了 Knative Eventing。
- 已配置了 Knative Broker。
-
已安装 Knative (
kn
) CLI。
流程
运行以下命令,将功能订阅给定代理的事件:
示例命令
$ kn func subscribe --filter type=com.example.Hello --source my-broker
使用--
source
标志指定代理以及一个或多个--filter
标志来指定您的过滤器。您还可以省略 the-
-source
标志以使用 default 代理:示例命令
$ kn func subscribe --filter type=com.example --filter extension=my-extension-value
使用 Knative Triggers 部署功能:
示例命令
$ kn func deploy
输出示例
🙌 Function image built: <registry>/hello:latest 🎯 Creating Triggers on the cluster ✅ Function deployed in namespace "default" and exposed at URL: http://hello.default.my-cluster.example.com