Skip to main content
VeloDB Cloud 26.x is based on Apache Doris 4.x. See Version Mapping.

Load Data from Kafka

VeloDB Cloud supports consuming data from Kafka in real time, which is commonly used for real-time data ingestion scenarios such as logs, orders, IoT events, and CDC sync. This document describes selection recommendations, usage limitations, and complete operational examples for the two mainstream approaches.

Before you begin​

For a guided Kafka import, see Import from Kafka. The console configures a Routine Load job for supported deployments. Use the SQL path below for direct job configuration, or run Doris Kafka Connector on your own Kafka Connect workers when your data format or pipeline requires it. See Load Overview for the overall choice.

Use a running warehouse and a SQL user with load privileges. For Routine Load, the warehouse must reach every broker address advertised by Kafka. For Kafka Connect, your workers must reach Kafka and the warehouse endpoints from Connect. Replace the sample hosts, ports, and credentials. Create and select the example databases and target tables before starting a job. Use distinct connector names when running the examples independently.

Approach selection​

VeloDB Cloud provides the following two ways to import data from Kafka:

ApproachApplicable ScenarioSupported FormatsFeatures
Routine LoadMost common scenarios, with no need to introduce external componentsCSV, JSONContinuously consumes a Kafka Topic, generates import tasks in real time, commits consumed offsets with load transactions for exactly-once ingestion within the job
Doris Kafka ConnectorImporting data in serialization formats such as Avro or Protobuf, or consuming upstream database CDC data collected by DebeziumJSON, Avro, Protobuf, DebeziumBuilt on the Kafka Connect plugin mechanism, with horizontal scalability and fault tolerance

Selection recommendations:

  • By default, prefer Routine Load, where VeloDB Cloud consumes Kafka directly. This is the simplest deployment.
  • When you need to consume formats such as Avro / Protobuf, or integrate with Kafka Connect ecosystem components such as Debezium, choose the Doris Kafka Connector.

Approach 1: use Routine Load to consume Kafka data​

Routine Load submits a long-running job in your warehouse that continuously consumes messages from a specified Kafka Topic and writes them into a warehouse table in real time.

Usage limitations​

  1. Only CSV and JSON message formats are supported. For CSV, each message is one row and the row does not include a trailing newline.
  2. Use Kafka 0.10.0.0 or later. If you must connect a legacy broker, confirm compatibility with VeloDB Cloud support. Do not modify warehouse BE configuration.

Operational example​

Use the CREATE ROUTINE LOAD command to create a long-running Routine Load import task. There are two scenarios: single-table import and multi-table import. For detailed syntax, refer to CREATE ROUTINE LOAD.

Scenario 1: single-table import​

Import data from one Kafka Topic into one table in your warehouse.

Step 1: Prepare Kafka data

Sample data in Kafka is as follows:

kafka-console-consumer.sh --bootstrap-server "<kafka-broker>:<kafka-port>" --topic test-routine-load-csv --from-beginning
1,Emily,25

Step 2: Create the target table in your warehouse

CREATE TABLE testdb.test_routineload_tbl(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "name",
age INT COMMENT "age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 10;

Step 3: Create the Routine Load job

Use the CREATE ROUTINE LOAD command to create the import job:

CREATE ROUTINE LOAD testdb.example_routine_load_csv ON test_routineload_tbl
COLUMNS TERMINATED BY ",",
COLUMNS(user_id, name, age)
FROM KAFKA(
"kafka_broker_list" = "<kafka-broker>:<kafka-port>",
"kafka_topic" = "test-routine-load-csv",
"property.kafka_default_offsets" = "OFFSET_BEGINNING"
);

Step 4: Check the import result

select * from test_routineload_tbl;
+-----------+----------------+------+
| user_id | name | age |
+-----------+----------------+------+
| 1 | Emily | 25 |
+-----------+----------------+------+

Scenario 2: multi-table import​

Use this scenario when you need to import data from the same Kafka Topic into multiple VeloDB Cloud tables at once.

Requirements and limitations:

  • The data in Kafka must include the table name, in the format table_name|data. For example, the CSV format is table_name|val1,val2,val3.
  • The table name must exactly match the table name in your warehouse, otherwise the import will fail.
  • Multi-table import does not support the column_mapping configuration.

Step 1: Prepare Kafka data

Sample data in Kafka is as follows (the prefix is the target table name):

kafka-console-consumer.sh --bootstrap-server "<kafka-broker>:<kafka-port>" --topic test-multi-table-load --from-beginning
test_multi_table_load1|1,Emily,25
test_multi_table_load2|2,Benjamin,35

Step 2: Create the target tables in your warehouse

Table 1:

CREATE TABLE test_multi_table_load1(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "user name",
age INT COMMENT "user age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 10;

Table 2:

CREATE TABLE test_multi_table_load2(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "user name",
age INT COMMENT "user age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 10;

Step 3: Create the multi-table Routine Load job

CREATE ROUTINE LOAD example_multi_table_load
COLUMNS TERMINATED BY ","
FROM KAFKA(
"kafka_broker_list" = "<kafka-broker>:<kafka-port>",
"kafka_topic" = "test-multi-table-load",
"property.kafka_default_offsets" = "OFFSET_BEGINNING"
);

Step 4: Check the import result

mysql> select * from test_multi_table_load1;
+---------+----------------+------+
| user_id | name | age |
+---------+----------------+------+
| 1 | Emily | 25 |
+---------+----------------+------+

mysql> select * from test_multi_table_load2;
+---------+----------------+------+
| user_id | name | age |
+---------+----------------+------+
| 2 | Benjamin | 35 |
+---------+----------------+------+

Configure security authentication​

If the Kafka cluster has SSL, SASL, or other security authentication enabled, refer to Kafka Security Authentication to configure the corresponding authentication parameters.

Approach 2: use Doris Kafka Connector to consume Kafka data​

Doris Kafka Connector is a tool built on the Kafka Connect framework that writes Kafka data streams into your warehouse. Through its plugin mechanism, it can easily import data in multiple serialization formats (such as JSON, Avro, and Protobuf), and supports parsing CDC data collected by Debezium.

Start in distributed mode​

Distributed mode provides scalability and automatic fault tolerance for Kafka Connect. In this mode, you can start multiple worker processes with the same group.id, and they coordinate scheduling of connectors and tasks.

Step 1: Place the plugin JAR

Create a plugins directory under $KAFKA_HOME and put the downloaded doris-kafka-connector JAR into it.

Step 2: Configure config/connect-distributed.properties

# Modify the broker address
bootstrap.servers=<kafka-broker>:<kafka-port>

# Modify the group.id; it must be the same within the same cluster
group.id=connect-cluster

# Change to the plugins directory you created
# Note: enter the direct path under Kafka here. For example: plugin.path=/opt/kafka/plugins
plugin.path=$KAFKA_HOME/plugins

# Example: allow 30 minutes between polls. Size this for worst-case processing and retries.
# The worker must remain within the poll interval while writing batches.
max.poll.interval.ms=1800000
consumer.max.poll.interval.ms=1800000

Step 3: Start Kafka Connect

$KAFKA_HOME/bin/connect-distributed.sh -daemon $KAFKA_HOME/config/connect-distributed.properties

Step 4: Submit the import task (consume Kafka data)

curl -i "<kafka-connect-endpoint>/connectors" -H "Content-Type: application/json" -X POST -d '{
"name":"test-doris-sink-cluster",
"config":{
"connector.class":"org.apache.doris.kafka.connector.DorisSinkConnector",
"topics":"topic_test",
"doris.topic2table.map": "topic_test:test_kafka_tbl",
"buffer.count.records":"10000",
"buffer.flush.time":"120",
"buffer.size.bytes":"5000000",
"doris.urls":"<warehouse-host>",
"doris.user":"<warehouse-user>",
"doris.password":"<warehouse-password>",
"doris.http.port":"<http-port>",
"doris.query.port":"<sql-port>",
"doris.database":"test_db",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"value.converter":"org.apache.kafka.connect.storage.StringConverter"
}
}'

Common Kafka Connect operations commands

OperationCommand
Check connector statuscurl -i "<kafka-connect-endpoint>/connectors/test-doris-sink-cluster/status" -X GET
Delete the current connectorcurl -i "<kafka-connect-endpoint>/connectors/test-doris-sink-cluster" -X DELETE
Pause the current connectorcurl -i "<kafka-connect-endpoint>/connectors/test-doris-sink-cluster/pause" -X PUT
Resume the current connectorcurl -i "<kafka-connect-endpoint>/connectors/test-doris-sink-cluster/resume" -X PUT
Restart a task within the connectorcurl -i "<kafka-connect-endpoint>/connectors/test-doris-sink-cluster/tasks/0/restart" -X POST

For more information about Distributed mode, refer to Distributed Workers.

Consume plain JSON data​

Use this for the scenario where Kafka stores plain JSON messages.

Step 1: Prepare Kafka data

Sample data in Kafka is as follows:

kafka-console-consumer.sh --bootstrap-server "<kafka-broker>:<kafka-port>" --topic test-data-topic --from-beginning
{"user_id":1,"name":"Emily","age":25}
{"user_id":2,"name":"Benjamin","age":35}
{"user_id":3,"name":"Olivia","age":28}
{"user_id":4,"name":"Alexander","age":60}
{"user_id":5,"name":"Ava","age":17}
{"user_id":6,"name":"William","age":69}
{"user_id":7,"name":"Sophia","age":32}
{"user_id":8,"name":"James","age":64}
{"user_id":9,"name":"Emma","age":37}
{"user_id":10,"name":"Liam","age":64}

Step 2: Create the target table in your warehouse

CREATE TABLE test_db.test_kafka_connector_tbl(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "name",
age INT COMMENT "age"
)
DUPLICATE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 12;

Step 3: Submit the import task

On the machine where Kafka Connect is deployed, submit the following import task using curl:

curl -i "<kafka-connect-endpoint>/connectors" -H "Content-Type: application/json" -X POST -d '{
"name":"test-doris-sink-cluster",
"config":{
"connector.class":"org.apache.doris.kafka.connector.DorisSinkConnector",
"tasks.max":"10",
"topics":"test-data-topic",
"doris.topic2table.map": "test-data-topic:test_kafka_connector_tbl",
"buffer.count.records":"10000",
"buffer.flush.time":"120",
"buffer.size.bytes":"5000000",
"doris.urls":"<warehouse-host>",
"doris.user":"<warehouse-user>",
"doris.password":"<warehouse-password>",
"doris.http.port":"<http-port>",
"doris.query.port":"<sql-port>",
"doris.database":"test_db",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"value.converter":"org.apache.kafka.connect.storage.StringConverter"
}
}'

Consume data collected by Debezium​

Use this for the scenario where Debezium collects change data (CDC) in real time from upstream databases such as MySQL or PostgreSQL and writes it into your warehouse.

Step 1: Prepare the source table and data in MySQL

CREATE TABLE test.test_user (
user_id int NOT NULL ,
name varchar(20),
age int,
PRIMARY KEY (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

insert into test.test_user values(1,'zhangsan',20);
insert into test.test_user values(2,'lisi',21);
insert into test.test_user values(3,'wangwu',22);

Step 2: Create the target table in your warehouse

CDC scenarios require the UNIQUE KEY table model to support primary key deduplication and deletion:

CREATE TABLE test_db.test_user(
user_id BIGINT NOT NULL COMMENT "user id",
name VARCHAR(20) COMMENT "name",
age INT COMMENT "age"
)
UNIQUE KEY(user_id)
DISTRIBUTED BY HASH(user_id) BUCKETS 12;

Step 3: Deploy Debezium MySQL Connector

Deploy the Debezium connector for MySQL component. Refer to Debezium connector for MySQL.

Step 4: Create the doris-kafka-connector import task

Suppose the MySQL table data collected by Debezium is stored in the mysql_debezium.test.test_user Topic:

curl -i "<kafka-connect-endpoint>/connectors" -H "Content-Type: application/json" -X POST -d '{
"name":"test-debezium-doris-sink",
"config":{
"connector.class":"org.apache.doris.kafka.connector.DorisSinkConnector",
"tasks.max":"10",
"topics":"mysql_debezium.test.test_user",
"doris.topic2table.map": "mysql_debezium.test.test_user:test_user",
"buffer.count.records":"10000",
"buffer.flush.time":"120",
"buffer.size.bytes":"5000000",
"doris.urls":"<warehouse-host>",
"doris.user":"<warehouse-user>",
"doris.password":"<warehouse-password>",
"doris.http.port":"<http-port>",
"doris.query.port":"<sql-port>",
"doris.database":"test_db",
"converter.mode":"debezium_ingestion",
"enable.delete":"true",
"key.converter":"org.apache.kafka.connect.json.JsonConverter",
"value.converter":"org.apache.kafka.connect.json.JsonConverter"
}
}'

Key parameters:

  • converter.mode=debezium_ingestion: enables parsing of the Debezium data format.
  • enable.delete=true: synchronously executes delete operations in your warehouse.

Consume data in Avro serialization format​

Use this for the scenario where Kafka stores data in Avro format together with a Schema Registry.

curl -i "<kafka-connect-endpoint>/connectors" -H "Content-Type: application/json" -X POST -d '{
"name":"doris-avro-test",
"config":{
"connector.class":"org.apache.doris.kafka.connector.DorisSinkConnector",
"topics":"avro_topic",
"tasks.max":"10",
"doris.topic2table.map": "avro_topic:avro_tab",
"buffer.count.records":"100000",
"buffer.flush.time":"120",
"buffer.size.bytes":"10000000",
"doris.urls":"<warehouse-host>",
"doris.user":"<warehouse-user>",
"doris.password":"<warehouse-password>",
"doris.http.port":"<http-port>",
"doris.query.port":"<sql-port>",
"doris.database":"test",
"load.model":"stream_load",
"key.converter":"io.confluent.connect.avro.AvroConverter",
"key.converter.schema.registry.url":"<schema-registry-endpoint>",
"value.converter":"io.confluent.connect.avro.AvroConverter",
"value.converter.schema.registry.url":"<schema-registry-endpoint>"
}
}'

Consume data in Protobuf serialization format​

Use this for the scenario where Kafka stores data in Protobuf format together with a Schema Registry.

curl -i "<kafka-connect-endpoint>/connectors" -H "Content-Type: application/json" -X POST -d '{
"name":"doris-protobuf-test",
"config":{
"connector.class":"org.apache.doris.kafka.connector.DorisSinkConnector",
"topics":"proto_topic",
"tasks.max":"10",
"doris.topic2table.map": "proto_topic:proto_tab",
"buffer.count.records":"100000",
"buffer.flush.time":"120",
"buffer.size.bytes":"10000000",
"doris.urls":"<warehouse-host>",
"doris.user":"<warehouse-user>",
"doris.password":"<warehouse-password>",
"doris.http.port":"<http-port>",
"doris.query.port":"<sql-port>",
"doris.database":"test",
"load.model":"stream_load",
"key.converter":"io.confluent.connect.protobuf.ProtobufConverter",
"key.converter.schema.registry.url":"<schema-registry-endpoint>",
"value.converter":"io.confluent.connect.protobuf.ProtobufConverter",
"value.converter.schema.registry.url":"<schema-registry-endpoint>"
}
}'

FAQ​

Q1: How should I choose between Routine Load and Doris Kafka Connector?

  • In most scenarios, Routine Load is sufficient: it requires no extra components and supports CSV and JSON.
  • If you need to consume Avro / Protobuf formats, or integrate with Kafka Connect ecosystem components such as Debezium, use the Doris Kafka Connector.

Q2: Which Kafka versions does Routine Load support?

Use Kafka 0.10.0.0 or later. For a legacy broker, confirm service compatibility with VeloDB Cloud support. Use job-level compatibility settings only for a service-supported broker version.

Q3: What format should the Kafka data be in for multi-table import?

The data format must be table_name|data. For example, the CSV multi-table import format is table_name|val1,val2,val3, and table_name must exactly match the table name in your warehouse, otherwise the import fails. Multi-table import does not support the column_mapping configuration.

Q4: When using Kafka Connect to consume, why should max.poll.interval.ms be increased?

Stream Load writes to VeloDB Cloud can take a long time. If max.poll.interval.ms (5 minutes by default) is too small, the consumer will be kicked out of the consumer group. Size it above the worst-case batch processing and retry duration, and set consumer.max.poll.interval.ms accordingly. The example uses 30 minutes; test an appropriate value for your workload.

Q5: How do I sync DELETE operations collected by Debezium to VeloDB Cloud?

In the Doris Kafka Connector configuration, set converter.mode=debezium_ingestion and enable.delete=true, and use the UNIQUE KEY table model in your warehouse to store CDC data.

See also​

Routine Load transaction semantics do not protect messages removed by Kafka retention before consumption or rows intentionally filtered by load settings. Monitor job state, lag, and rejected rows, and retain source data long enough for recovery.