Chapter 11. Subscribing functions to CloudEvents


You can subscribe a function to a set of events. This links your function to CloudEvent objects defined by your filters and enables automated responses.

11.1. Subscribing a function to CloudEvents

The subscribe command connects the function to events by matching filters for CloudEvent metadata and using a Knative Broker as the source. The function then consumes events from the broker.

Prerequisites

  • You have installed Knative Eventing on the cluster.
  • You have configured a Knative Broker.
  • You have installed the Knative (kn) CLI.

Procedure

  1. Subscribe the function to events for a given broker by running the following command:

    You get an output similar to the following example command:

    $ kn func subscribe --filter type=com.example.Hello --source my-broker

    Use the --source flag to specify the broker and one or more --filter flags to specify your filters.

    You can also omit the --source flag to use the default broker:

    You get an output similar to the following example command:

    $ kn func subscribe --filter type=com.example --filter extension=my-extension-value
  2. Deploy the function with Knative Triggers:

    You get an output similar to the following example command:

    $ kn func deploy

    You get an output similar to the following example:

    🙌 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
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top