订阅函数到 CloudEvents¶
先决条件¶
- 集群中已安装 Knative Eventing
步骤¶
subscribe 命令会将函数连接到一组事件,这些事件会匹配一系列 Cloud Event 元数据过滤器以及作为事件源的 Knative Broker,然后从那里进行消费。
要将函数订阅到给定 Broker 的事件,请运行以下命令
func subscribe --filter type=com.example --filter extension=my-extension-value --source my-broker
要将函数订阅到默认 Broker 的事件,请运行以下命令
func subscribe --filter type=com.example --filter extension=my-extension-value
要将函数订阅到给定 Broker 的事件,请运行以下命令
kn func subscribe --filter type=com.example --filter extension=my-extension-value --source my-broker
要将函数订阅到默认 Broker 的事件,请运行以下命令
kn func subscribe --filter type=com.example --filter extension=my-extension-value
使用触发器进行部署¶
调用 func deploy 时,CLI 将为该函数创建 Knative 触发器。
通过在项目目录中运行命令来部署带有触发器的函数
func deploy
通过在项目目录中运行命令来部署带有触发器的函数
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.127.0.0.1.sslip.io