跳到内容

订阅函数到 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

我们使用分析和 cookie 来了解网站流量。有关您使用我们网站的信息会与 Google 共享以达到此目的。了解更多。