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.
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
-
From the the top right corner of the OpenShift console, click on the (+) button and then Import Yaml dropdown option
-
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: /analyzeYou might notice that both the moderate-reviews-triggerandsentiment-reviews-triggerhave 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). -
You will note the triggers have been created successfully
-
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
-
Click on the Broker
globex-brokerto 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.