Using triggers enables you to filter events from the broker for delivery to event sinks.

Prerequisites

  • You have installed Knative Eventing and the kn CLI.

  • You have access to an available broker.

  • You have access to an available event consumer, such as a Knative service.

Creating a trigger using the Developer perspective

After you have created a broker, you can create a trigger in the web console Developer perspective.

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

  • You have logged in to the web console.

  • You are in the Developer perspective.

  • 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 Container Platform.

  • 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.

    Create a trigger for the broker
  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, it is represented as a line that connects the broker to the service in the Topology view:

    Trigger in the Topology view

Deleting a trigger using the Developer perspective

You can delete triggers in the web console Developer perspective.

Prerequisites
  • To delete a trigger using the Developer perspective, ensure that you have logged in to the web console.

Procedure
  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.

    Delete a trigger

Creating a trigger by using the Knative CLI

You can create a trigger by using the kn trigger create command.

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

  • You have installed the kn CLI.

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

The kn trigger list command prints a list of available triggers.

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

  • You have installed the 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