Kafka Engine Configuration
Apache Kafka is a streaming data platform that serves as the log engine in DataSQRL pipelines for handling data streams and event logs.
Configuration Optionsโ
| Key | Type | Default | Description |
|---|---|---|---|
retention | string or null | null | Topic retention time (e.g., "7d", "24h"); null or "-1" retains data indefinitely |
watermark | string | "0 ms" | Watermark delay for event time processing |
transaction-watermark | string | "0 ms" | Watermark delay for event time processing when transactions are enabled |
use-source-watermark | boolean | false | Use Flink's SOURCE_WATERMARK() for non-transactional Kafka tables |
use-transaction-source-watermark | boolean | false | Use Flink's SOURCE_WATERMARK() for transactional Kafka tables |
num-partitions | integer | 1 | Number of partitions for generated Kafka topics |
replication-factor | integer | 3 | Replication factor for generated Kafka topics |
Example Configurationโ
{
"engines": {
"kafka": {
"retention": "14d",
"watermark": "2 sec",
"transaction-watermark": "10 sec",
"use-source-watermark": true,
"use-transaction-source-watermark": true,
"num-partitions": 4,
"replication-factor": 3
}
}
}
Usage Notesโ
- Kafka topics are automatically created based on your SQRL table definitions
- Topic configurations are generated during the compilation process
kafka.jsonlists the topics that a standalone included project writes and the current project uses underincludedTopics, with only their names, because that project owns them and decides their settings: the topics of its internal Kafka tables and of the subscriptions that its deployment exposes. Flink does not write those subscription topics, and the include'sEXPORTandINSERTstatements into the log, its internal Kafka tables and external tables don't run, because the included project's deployment runs them- Only the mutation table writes its Kafka topic. Another writer mixes its rows into the mutation, and a writer that reads the mutation reads its own output in an endless loop. When the
kafkaconnector template gives a Kafka table that the compiler creates for Flink the topic of a mutation table, the compiler puts<table-name>-subscriptionin place of${sqrl:table-name}in the template'stopicinstead, soacme-${sqrl:table-name}givesacme-Events-subscription. If the template gives a mutation topic again, for example with a fixedtopicwithout${sqrl:table-name}, the compile fails with an error. For example, a script defines the mutation tableEventswithCREATE TABLEand theengine(kafka)hint, and aSUBSCRIBEfunction readsEventsdirectly. Flink then copiesEventsinto a Kafka table for the subscription. With the default templates, the mutation topic isEventsand the copy gets the topicEvents-subscription. AnEXPORTstatement tolog.<name>orlogger.<name>that gets the topic of a mutation table fails with an error, for exampleEXPORT Orders TO log.EventswhenEventsis a mutation table. Use a different name in theEXPORTstatement. All other topics keep the name from the template. The compiler does not check anEXPORTstatement that writes directly into a mutation table, such asEXPORT _Echo TO Events. When the exported query reads that mutation table, the export loops - Retention settings control how long data is stored in Kafka topics
- Ensure
replication-factordoes not exceed the number of brokers in the target Kafka cluster - Watermarks are used for handling late-arriving events in stream processing
- Source watermarks apply only to mutation tables with a
timestampmetadata column. When enabled, they generateWATERMARK FOR <timestamp-column> AS SOURCE_WATERMARK()instead of using the corresponding watermark delay. It is only supported by ourkafka-safeandupsert-kafka-safeconnectors. - Kafka serves as the messaging backbone between different engines in the pipeline
Key and Value Formatsโ
The kafka and kafka-mutation connector templates set one format (flexible-json by default) for the message key and value. To use separate formats, set key.format and value.format in the template, or in the WITH options of an internal table:
{
"connectors": {
"kafka-mutation": {
"key.format": "json",
"value.format": "flexible-json"
}
}
}
key.formatandvalue.formattake precedence overformat, which the default template always contains.- Tables with a message key (
PARTITIONED BYor a primary key) usekey.formatfor the key, otherwiseformat, otherwisevalue.format. Tables without a message key dropkey.format. - Options of
format, such asflexible-json.timestamp-format.standard, apply only to the key or value that uses that format. Set an option for one side with akey.orvalue.prefix, for examplevalue.flexible-json.timestamp-format.standard. - When
key.formatandvalue.formatare the same, the compiler notes thatformatis enough. - The server writes mutations as JSON, so the compiler warns when a mutation table uses a format other than
jsonorflexible-json.
Internal Environment Variablesโ
When running pipelines with the DataSQRL run command, the following environment variables are used
in the configuration:
KAFKA_BOOTSTRAP_SERVERSKAFKA_GROUP_ID