Skip to main content

Kafka Reference

Authentication options and data type handling for Kafka connections.

Authentication

VariableExampleDescription
DATACONTRACT_KAFKA_SASL_USERNAMExxxThe SASL username (key)
DATACONTRACT_KAFKA_SASL_PASSWORDxxxThe SASL password (secret)
DATACONTRACT_KAFKA_SASL_MECHANISMPLAINDefault PLAIN; also SCRAM-SHA-256, SCRAM-SHA-512

If no username/password is set, the CLI connects without authentication (e.g. a local broker). host, topic, and format come from the contract's servers block. Kafka checks run on Spark and require a JDK (17 or 21).

Data types

Importing

For Avro-encoded topics, import the schema with datacontract import avro. The Avro type is kept as physicalType:

Avro typelogicalType
stringstring
int, longinteger
float, doublenumber
booleanboolean
recordobject with nested properties
arrayarray
mapobject (values not expanded)
enumstring (symbols in the avroSymbols custom property)
bytes, fixedarray

Avro logical type annotations take precedence: decimalnumber (with precision/scale), datedate, uuid/duration/time-millis/time-microsstring. Unions must be [null, T] and make the field optional.

Testing

Messages are read via Spark. For format: json and format: avro, no type checks are generated — messages are decoded as the contract's types, and violations surface as decode errors or value-check failures from logicalTypeOptions.