Knatve Sink and SinkBinding
In this section we will connect the Knative Services (refer to previous section) to Kafka using Knative Sink and SinkBinding.
SinkBinding supports decoupling the source (service which produces events) from the actual sink by injecting the sink URL into the services. |
1. Create Sink and SinkBinding
This solution needs a number of Sinks and SinkBinding for the various Kafka topics described in an earlier section. You will create one of them here, while the others have been preconfigured for you.
Here is a visual of how the reviews flows from the User to Kafka with Knative eventing.
-
The reviews submitted by the user are sent to the
product_reviews
Quarkus service through HTTP POST. -
The
product_reviews
service sends this review as a CloudEvent to thereviews-sink
Kafka Sink over HTTP. -
The Quarkus service remains agnostic to the internals of the Kafka streaming platform.
-
The
reviews-sink
Kafka Sink sends this Cloud Event to theglobex.reviews
Kafka topic.

Now, go ahead and create the Sink and SinkBinding.
-
Navigate to OpenShift console {openshift_cluster_console}[OpenShift Console^, window="console"] and if needed login with ({user_name}/{user_password}).
-
From the the top right corner of the OpenShift console, click on the (+) button and then Import Yaml dropdown option
-
Copy the following YAML into the Import YAML form, and click Create to create the KafkaSink
reviews-sink
which will send messages toglobex.reviews
Kafka Topic.apiVersion: eventing.knative.dev/v1alpha1 kind: KafkaSink metadata: name: reviews-sink namespace: globex-serverless-{user_name} spec: bootstrapServers: - kafka-kafka-bootstrap.globex-mw-{user_name}.svc.cluster.local:9092 topic: globex.reviews numPartitions: 1 contentMode: binary auth: secret: ref: name: kafka-secret
-
Use the Import YAML form to create a Sink Binding from the
product-reviews
Quarkus Service to the KafkaSinkreviews-sink
that you created in the previous step.apiVersion: sources.knative.dev/v1 kind: SinkBinding metadata: name: product-reviews-to-reviews-sink namespace: globex-serverless-{user_name} spec: sink: ref: apiVersion: eventing.knative.dev/v1alpha1 kind: KafkaSink name: reviews-sink namespace: globex-serverless-{user_name} subject: apiVersion: apps/v1 kind: Deployment name: product-reviews namespace: globex-serverless-{user_name}
-
Navigate back to the {openshift_cluster_console}/topology/ns/globex-serverless-{user_name}?view=graph[Topology View, window="console", target="console"], to view the new Sink and SinkBinding you created
-
Here is the list of all the Kafka Sinks used in this solution.
Sink name
Function
reviews-sink
Send the reviews submitted by user (HTTP POST from
globex-web
app toproduct-reviews
Quarkus service) as CloudEvents toglobex.reviews
Kafka topicmoderated-reviews-sink
Sends reviews moderated by the
aiml-moderate-reviews
service to topicreviews.moderated
reviews-sentiment-sink
Sends sentiment score of reviews by the
aiml-sentiment-reviews
service to topicreviews.sentiment