×

您可以将函数订阅到一组事件。这会将您的函数链接到由您的过滤器定义的CloudEvent对象,并启用自动响应。

将函数订阅到 CloudEvents

subscribe命令将函数连接到一组事件,匹配一系列CloudEvent元数据的过滤器和作为事件源的 Knative Broker,从中消费事件。

前提条件
  • 您已在集群上安装 Knative Eventing。

  • 您已配置 Knative Broker。

  • 您已安装 Knative (kn) CLI。

步骤
  1. 通过运行以下命令将函数订阅到给定代理的事件

    示例命令
    $ kn func subscribe --filter type=com.example.Hello --source my-broker

    使用--source标志指定代理,并使用一个或多个--filter标志指定您的过滤器。

    您也可以省略--source标志以使用默认代理

    示例命令
    $ kn func subscribe --filter type=com.example --filter extension=my-extension-value
  2. 使用 Knative 触发器部署函数

    示例命令
    $ 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