×

Brokers can be used in combination with triggers to deliver events from an event source to an event sink. Events are sent from an event source to a broker as an HTTP POST request. After events have entered the broker, they can be filtered by CloudEvent attributes using triggers, and sent as an HTTP POST request to an event sink.

Broker event delivery overview

Creating a trigger by using the web console

Using the OpenShift Dedicated web console provides a streamlined and intuitive user interface to create a trigger. After Knative Eventing is installed on your cluster and you have created a broker, you can create a trigger by using the web console.

Prerequisites
  • The OpenShift Serverless Operator, Knative Serving, and Knative Eventing are installed on your OpenShift Dedicated cluster.

  • You have logged in to the web console.

  • You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Dedicated.

  • You have created a broker and a Knative service or other event sink to connect to the trigger.

Procedure
  1. In the Developer perspective, navigate to the Topology page.

  2. Hover over the broker that you want to create a trigger for, and drag the arrow. The Add Trigger option is displayed.

  3. Click Add Trigger.

  4. Select your sink as a Subscriber from the drop-down list.

  5. Click Add.

Verification
  • After the subscription has been created, you can view it in the Topology page, where it is represented as a line that connects the broker to the event sink.

Deleting a trigger
  1. In the Developer perspective, navigate to the Topology page.

  2. Click on the trigger that you want to delete.

  3. In the Actions context menu, select Delete Trigger.

Creating a trigger by using the Knative CLI

Using the kn CLI to create triggers provides a more streamlined and intuitive user interface over modifying YAML files directly. You can use the kn trigger create command to create a trigger by using the kn CLI.

Prerequisites
  • The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Dedicated cluster.

  • You have installed the Knative (kn) CLI.

  • You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Dedicated.

Procedure
  • Create a trigger:

    $ kn trigger create <trigger_name> --broker <broker_name> --filter <key=value> --sink <sink_name>

    Alternatively, you can create a trigger and simultaneously create the default broker using broker injection:

    $ kn trigger create <trigger_name> --inject-broker --filter <key=value> --sink <sink_name>

    By default, triggers forward all events sent to a broker to sinks that are subscribed to that broker. Using the --filter attribute for triggers allows you to filter events from a broker, so that subscribers will only receive a subset of events based on your defined criteria.

Listing triggers by using the Knative CLI

Using the kn CLI to list triggers provides a streamlined and intuitive user interface. You can use the kn trigger list command to list existing triggers in your cluster.

Prerequisites
  • The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Dedicated cluster.

  • You have installed the Knative (kn) CLI.

Procedure
  1. Print a list of available triggers:

    $ kn trigger list
    Example output
    NAME    BROKER    SINK           AGE   CONDITIONS   READY   REASON
    email   default   ksvc:edisplay   4s    5 OK / 5     True
    ping    default   ksvc:edisplay   32s   5 OK / 5     True
  2. Optional: Print a list of triggers in JSON format:

    $ kn trigger list -o json

Describing a trigger by using the Knative CLI

Using the kn CLI to describe triggers provides a streamlined and intuitive user interface. You can use the kn trigger describe command to print information about existing triggers in your cluster by using the kn CLI.

Prerequisites
  • The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Dedicated cluster.

  • You have installed the Knative (kn) CLI.

  • You have created a trigger.

Procedure
  • Enter the command:

    $ kn trigger describe <trigger_name>
    Example output
    Name:         ping
    Namespace:    default
    Labels:       eventing.knative.dev/broker=default
    Annotations:  eventing.knative.dev/creator=kube:admin, eventing.knative.dev/lastModifier=kube:admin
    Age:          2m
    Broker:       default
    Filter:
      type:       dev.knative.event
    
    Sink:
      Name:       edisplay
      Namespace:  default
      Resource:   Service (serving.knative.dev/v1)
    
    Conditions:
      OK TYPE                  AGE REASON
      ++ Ready                  2m
      ++ BrokerReady            2m
      ++ DependencyReady        2m
      ++ Subscribed             2m
      ++ SubscriberResolved     2m

Filtering events with triggers by using the Knative CLI

Using the kn CLI to filter events by using triggers provides a streamlined and intuitive user interface. You can use the kn trigger create command, along with the appropriate flags, to filter events by using triggers.

In the following trigger example, only events with the attribute type: dev.knative.samples.helloworld are sent to the event sink:

$ kn trigger create <trigger_name> --broker <broker_name> --filter type=dev.knative.samples.helloworld --sink ksvc:<service_name>

You can also filter events by using multiple attributes. The following example shows how to filter events using the type, source, and extension attributes:

$ kn trigger create <trigger_name> --broker <broker_name> --sink ksvc:<service_name> \
--filter type=dev.knative.samples.helloworld \
--filter source=dev.knative.samples/helloworldsource \
--filter myextension=my-extension-value

Updating a trigger by using the Knative CLI

Using the kn CLI to update triggers provides a streamlined and intuitive user interface. You can use the kn trigger update command with certain flags to update attributes for a trigger.

Prerequisites
  • The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Dedicated cluster.

  • You have installed the Knative (kn) CLI.

  • You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Dedicated.

Procedure
  • Update a trigger:

    $ kn trigger update <trigger_name> --filter <key=value> --sink <sink_name> [flags]
    • You can update a trigger to filter exact event attributes that match incoming events. For example, using the type attribute:

      $ kn trigger update <trigger_name> --filter type=knative.dev.event
    • You can remove a filter attribute from a trigger. For example, you can remove the filter attribute with key type:

      $ kn trigger update <trigger_name> --filter type-
    • You can use the --sink parameter to change the event sink of a trigger:

      $ kn trigger update <trigger_name> --sink ksvc:my-event-sink

Deleting a trigger by using the Knative CLI

Using the kn CLI to delete a trigger provides a streamlined and intuitive user interface. You can use the kn trigger delete command to delete a trigger.

Prerequisites
  • The OpenShift Serverless Operator and Knative Eventing are installed on your OpenShift Dedicated cluster.

  • You have installed the Knative (kn) CLI.

  • You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in OpenShift Dedicated.

Procedure
  • Delete a trigger:

    $ kn trigger delete <trigger_name>
Verification
  1. List existing triggers:

    $ kn trigger list
  2. Verify that the trigger no longer exists:

    Example output
    No triggers found.