How to Push Messages with Alibaba Cloud Kafka in Knative: A Step‑by‑Step Guide
This tutorial explains how to create an Alibaba Cloud Kafka instance, configure topics and consumer groups, deploy the Knative Kafka addon, define a Knative Service and KafkaSource, and verify message delivery using CloudEvents, enabling serverless event‑driven applications.
Background
Knative now supports Kafka event sources. This guide shows how to use Alibaba Cloud Message Queue for Apache Kafka to push messages into Knative services.
Create a Kafka instance on Alibaba Cloud
Log in to the Message Queue for Apache Kafka console, purchase a professional version (annual/monthly) that supports version 2.0.0 or later, then deploy the instance and bind it to the VPC where the Knative cluster resides.
Create Topic and Consumer Group
In the console, go to Topic Management and create a topic named demo. Then go to Consumer Group Management and create a consumer group named demo-consumer.
Deploy the Kafka addon component
In the Container Service console, open Knative Component Management and deploy the Kafka addon.
Create a Knative Service to receive events
Define a Knative Service named event-display that runs the sample event‑display container image.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/knative-sample/eventing-sources-cmd-event_display:bf45b3eb1e7fc4cb63d6a5a6416cf696295484a7662e0cf9ccdf5c080542c21dCreate the KafkaSource
Apply a KafkaSource that points to the previously created topic and consumer group, and routes events to the event-display service.
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: KafkaSource
metadata:
name: alikafka-source
spec:
consumerGroup: demo-consumer
bootstrapServers: 192.168.0.6x:9092,192.168.0.7x:9092,192.168.0.8x:9092
topics: demo
sink:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: event-display bootstrapServers: VPC‑accessible Kafka broker addresses consumerGroup: name of the consumer group topics: topic to subscribe
Verify the setup
Send a JSON message to the demo topic via the Kafka console. The event‑display service receives the CloudEvent and logs show the payload.
# kubectl logs event-display-... user-container
☁️ CloudEvent: valid ✅
Context Attributes,
SpecVersion: 0.2
Type: dev.knative.kafka.event
Source: /apis/v1/namespaces/default/kafkasources/alikafka-source#demo
ID: partition:7/offset:1
Time: 2019-10-18T08:50:32.492Z
ContentType: application/json
Extensions:
key: demo
Data,
{"key":"test"}Conclusion
By combining Alibaba Cloud Kafka with Knative Eventing, you can trigger serverless services with high‑throughput, low‑latency messages in a simple, cloud‑native way.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
