Knative triggers

1. Create Knative triggers

You will now create triggers which will invoke the HTTP endpoint of Knative services depending on the CloudEvents headers.

The red box in the diagram below highlights the Knative triggers with filter and its bindings that you will be creating within this section.

arch highlight trigger filter

Each CloudEvents created will be tagged with specific values in the headers ce-type and ce-source which is then used by the Trigger to route them to the correct service HTTP endpoint

  1. From the the top right corner of the OpenShift console, click on the (+) button and then Import Yaml dropdown option

  2. Copy and paste the following CRD to create the 3 Triggers matching the 3 Knative services

    apiVersion: eventing.knative.dev/v1
    kind: Trigger
    metadata:
      name: persist-reviews-trigger
      namespace: globex-serverless-{user_name}
    spec:
      broker: globex-broker
      filter:
        attributes:
          source: review-moderated
          type: review-moderated-event
      subscriber:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: persist-reviews
        uri: /review/submit
    
    ---
    apiVersion: eventing.knative.dev/v1
    kind: Trigger
    metadata:
      name: moderate-reviews-trigger
      namespace: globex-serverless-{user_name}
    spec:
      broker: globex-broker
      filter:
        attributes:
          source: submit-review
          type: submit-review-event
      subscriber:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: aiml-moderate-reviews
        uri: /analyze
    ---
    apiVersion: eventing.knative.dev/v1
    kind: Trigger
    metadata:
      name: sentiment-reviews-trigger
      namespace: globex-serverless-{user_name}
    spec:
      broker: globex-broker
      filter:
        attributes:
          source: submit-review
          type: submit-review-event
      subscriber:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: aiml-sentiment-reviews
        uri: /analyze
    You might notice that both the moderate-reviews-trigger and sentiment-reviews-trigger have the same filter attributes. This is because both the corresponding services need to act on the same event (i.e when a review is submitted).
  3. You will note the triggers have been created successfully

    triggers created
  4. Navigate back to the {openshift_cluster_console}/topology/ns/globex-serverless-{user_name}?view=graph[Topology View, window="console"], to view the new triggers you created

    triggers create topology
  5. Click on the Broker globex-broker to view how the three Knative services subscribe to the KnativeBroker using the Triggers; also note the various filters applied to the triggers.
    These filters are the ones which help to match the CloudEvents header of each message to the right service which will act on the message.

    broker service filters