Knotive practice: message push based on Kafka

Author: Yuanyi, senior development engineer of Alibaba cloud intelligent business group

Introduction: Currently, Kafka event sources are supported in knight. How to implement message push based on Kafka? The author of this article will take Alibaba cloud Kafka products as an example to unlock this new posture.


Message queuing for Apache Kafka is a distributed, high throughput and scalable Message Queuing service provided by alicloud. Message queuing for Apache Kafka is widely used in log collection, monitoring data aggregation, streaming data processing, online and offline analysis and other big data fields, and has become an indispensable part of big data ecology.

Combined with the support of KafkaSource event source provided in Knight, Kafka message service can be easily docked.

You can also install community Kafka 2.0.0 and above.

Create Kafka instance on alicloud

Create Kafka instance

Sign in Message queuing Kafka console , select purchase instance. Since the current Kafka event source in known supports version 2.0.0 and above, creating Kafka instances on Alibaba cloud requires purchasing the yearly, monthly and professional versions, and upgrading to 2.0.0 after purchase.

Deploy instance and bind VPC

After purchase, deploy. When deploying, set the VPC where the knowledgeable cluster is located.

Create Topic and Consumer Group

Next, we create topics and consumption groups. < br / > Enter topic management and click Create topic. Here we create a topic named demo:

Enter Consumer Group management, and click create Consumer Group. Here we create a Consumer Group named demo consumer:

Deploy Kafka data source

Deploy Kafka addon components

Log in to the container service console, enter "knowledge component management", and deploy Kafka addon component.

Create KafkaSource instance

First, create the service event display for receiving events:

kind: Service
  name: event-display
      - image:

Next, create KafkaSource:

kind: KafkaSource
  name: alikafka-source
  consumerGroup: demo-consumer
  # Broker URL. Replace this with the URLs for your kafka cluster,
  # which is in the format of
  topics: demo
    kind: Service
    name: event-display


  • Bootstrap servers: Kafka VPC access address
  • consumerGroup: set consumption group
  • Topic s: setting topics

After creation, we can check that the corresponding instance has been run:

[root@iZ2zeae8wzyq0ypgjowzq2Z ~]# kubectl get pods
NAME                                    READY   STATUS    RESTARTS   AGE
alikafka-source-k22vz-db44cc7f8-879pj   1/1     Running   0          8h

<a name="cd8992b6"></a>


In the Kafka console, select topic to send the message. Note that the message format here must be json format:

We can see that we have received the Kafka message:

[root@iZ2zeae8wzyq0ypgjowzq2Z ~]# kubectl logs event-display-zl6m5-deployment-6bf9596b4f-8psx4 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
    key: demo
Transport Context,
  URI: /
  Host: event-display.default.svc.cluster.local
  Method: POST
    "key": "test"

<a name="5db9fd7c"></a>


Combined with Alibaba cloud Kafka products, is it simple and efficient to trigger service (function) execution through event driven? In this way, we can fully release the cloud's native ability by using knight, and bring us more imagination space. Welcome to communicate with people who are interested in knight.

Link to demonstration of operation video:

About the author: Yuan Yi, senior development engineer of Alibaba cloud container platform, is responsible for the work related to the knowledge of Alibaba cloud container platform.

Welcome to the interactive group

"Alibaba cloud native wechat public account (ID: Alicloudnative) focuses on the technology fields such as microservice, Serverless, container, Service Mesh, the trend of jujiao cloud native popular technology, the large-scale implementation practice of cloud native, and makes the technical public account that most understands cloud native developers."

Keywords: kafka VPC Apache Big Data

Added by faraway on Fri, 25 Oct 2019 09:54:09 +0300