Kafka Consumer Streaming Source

Plugin version: 3.2.0

Kafka streaming source. Emits a record with the schema specified by the user. If no schema is specified, it will emit a record with two fields: ‘key’ (nullable string) and ‘message’ (bytes). This plugin uses kafka 2.6 java apis.

This source is used whenever you want to read from Kafka. For example, you may want to read messages from Kafka and write them to a Table.

If the Kafka instance is SSL enabled, see Reading from and writing to SSL enabled Apache Kafka for additional configuration information.

Configuration

Property

Macro Enabled?

Description

Property

Macro Enabled?

Description

Reference Name

No

Required. This will be used to uniquely identify this source for lineage, annotating metadata, etc.

Kafka Brokers

Yes

Required. List of Kafka brokers specified in host1:port1,host2:port2 form.

Kafka Topic

Yes

Required. The Kafka topic to read from.

Topic Partitions

Yes

Optional. List of topic partitions to read from. If not specified, all partitions will be read.

Initial Offset

Yes

Optional. The default initial offset for all topic partitions. An offset of -2 means the smallest offset. An offset of -1 means the latest offset. Defaults to -1. Offsets are inclusive. If an offset of 5 is used, the message at offset 5 will be read. If you wish to set different initial offsets for different partitions, use the initialPartitionOffsets property.

Initial Partition Offsets

Yes

Optional. The initial offset for each topic partition. If this is not specified, all partitions will use the same initial offset, which is determined by the defaultInitialOffset property. Any partitions specified in the partitions property, but not in this property will use the defaultInitialOffset. An offset of -2 means the smallest offset. An offset of -1 means the latest offset. Offsets are inclusive. If an offset of 5 is used, the message at offset 5 will be read.

Time Field

No

Optional. Name of the field containing the read time of the batch. If this is not set, no time field will be added to output records. If set, this field must be present in the schema property and must be a long.

Key Field

No

Optional. Name of the field containing the message key. If this is not set, no key field will be added to output records. If set, this field must be present in the schema property and must be bytes.

Partition Field

No

Optional. Name of the field containing the partition the message was read from. If this is not set, no partition field will be added to output records. If set, this field must be present in the schema property and must be an int.

Offset Field

No

Optional. Name of the field containing the partition offset the message was read from. If this is not set, no offset field will be added to output records. If set, this field must be present in the schema property and must be a long.

Max Rate Per Partition

No

Optional. Maximum number of records to read per second per partition.

Default is 1000.

Additional Kafka Consumer Properties

Yes

Optional. Additional Kafka properties to set.

Format

No

Optional. Format of the Kafka event message. Any format supported by CDAP is supported. For example, a value of ‘csv’ will attempt to parse Kafka payloads as comma-separated values. If no format is given, Kafka message payloads will be treated as bytes.

Kerberos Principal

Yes

Optional. The kerberos principal used for the source when kerberos security is enabled for Kafka.

Keytab Location

Yes

Optional. The keytab location for the kerberos principal when kerberos security is enabled for Kafka.

Output Schema

No

Required. Output schema of the source. If you would like the output records to contain a field with the Kafka message key, the schema must include a field of type bytes or nullable bytes, and you must set the keyField property to that field’s name. Similarly, if you would like the output records to contain a field with the timestamp of when the record was read, the schema must include a field of type long or nullable long, and you must set the timeField property to that field’s name. Any field that is not the timeField or keyField will be used in conjunction with the format to parse Kafka message payloads.

Example

This example reads from the ‘purchases’ topic of a Kafka instance running on brokers host1.example.com:9092 and host2.example.com:9092. The source will add a time field named ‘readTime’ that contains a timestamp corresponding to the micro batch when the record was read. It will also contain a field named ‘key’ which will have the message key in it. It parses the Kafka messages using the ‘csv’ format with ‘user’, ‘item’, ‘count’, and ‘price’ as the message schema.

Property

Value

Property

Value

Reference Name

kafka

Kafka Brokers

host1.example.com:9092,host2.example.com:9092

Kafka Topics

purchases

Time Field

readTime

Key Field

key

Format

csv

For each Kafka message read, it will output a record with the schema:

field name

type

field name

type

readTime

long

key

bytes

user

string

item

string

count

int

price

double

Note that the readTime field is not derived from the Kafka message, but from the time that the message was read.



 

Created in 2020 by Google Inc.