key deserializer doc for kafka source (#2140)

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
Francesco Guardiani 2020-02-14 23:24:49 +01:00 committed by GitHub
parent c3019c2561
commit 8890fb6f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

View File

@ -221,3 +221,34 @@ You must ensure that you meet the [prerequisites listed in the Apache Kafka over
$ kubectl delete -f kafka/source/samples/kafka-topic.yaml
kafkatopic.kafka.strimzi.io "knative-demo-topic" deleted
```
## (Optional) Specify the key deserializer
When `KafkaSource` receives a message from Kafka, it dumps the key in the Event extension called `Key` and dumps Kafka message headers in the extensions starting with `kafkaheader`.
You can specify the key deserializer among four types:
* `string` (default) for UTF-8 encoded strings
* `int` for 32-bit & 64-bit signed integers
* `float` for 32-bit & 64-bit floating points
* `byte-array` for a Base64 encoded byte array
To specify it, add the label `kafkasources.sources.eventing.knative.dev/key-type` to the `KafkaSource` definition like:
```yaml
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: KafkaSource
metadata:
name: kafka-source
labels:
kafkasources.sources.eventing.knative.dev/key-type: int
spec:
consumerGroup: knative-group
bootstrapServers: my-cluster-kafka-bootstrap.kafka:9092 #note the kafka namespace
topics: knative-demo-topic
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
```