Write your first record from Kafka
Kafka ingestion reads messages from specified topics, parses and maps them, and writes them to TDengine. This example uses a dedicated test topic and two temperature messages: first verify the initial write, then confirm continuous consumption. Configure a production task only after both queries return the expected results.
Where to operate: taosExplorer → Data Ingestion. Run preparation and verification SQL in the target cluster's Data Browser or taos CLI.
taosX actually reads Kafka, or the selected taosX-Agent does so when the task uses a proxy. This section uses taosX directly and requires Kafka topic read permissions, task management permissions, and target database write permissions. An authorized TDengine TSDB administrator creates the database and supertable in advance.
Use a dedicated test topic and a new consumer group to avoid sharing messages with existing collection tasks. Samples on the configuration page only preview parsing and mapping. Messages must also be sent to Kafka.
1. Prerequisites
- Confirm that taosExplorer is accessible and SQL can be executed on the target cluster.
- Prepare a dedicated Kafka topic for this test, such as
taosx_quickstart, and record the broker addresses and authentication settings. The actual reading host must be able to reach the addresses returned by the brokers; reaching only the initial connection address is not enough. If Kafka is not already available, use the optional test environment setup below. - Create the target database and supertable, and confirm that at least one Xnode is online:
In this example, an authorized TDengine TSDB administrator creates the database and supertable in advance. With the taosExplorer Data Browser, log in to the target cluster and execute the SQL below directly; taos CLI installation is unnecessary. Alternatively, use taos CLI on a host where it is installed to connect to the target cluster.
For taos CLI, use the login command for the platform below. These commands apply only to isolated test environments where the default password has not been changed. In production, use an authorized account and enter the password at the prompt, not in command history.
- Linux
- Windows
Run in Bash, with taos CLI installed and in PATH:
taos -h localhost -P 6030 -u root -p
Run in PowerShell. If the installation directory is not C:\TDengine, use the actual path:
& 'C:\TDengine\taos.exe' -h localhost -P 6030 -u root -p
At the password prompt, enter default password taosdata, or the actual password if it has changed. Here, localhost:6030 refers to target taosd on the taos CLI host. For remote access, use the target host and actual port, and ensure the node addresses returned by the cluster are reachable.
Run the following SQL in the taosExplorer Data Browser or taos CLI. If objects with these names exist, use new dedicated test names and update the task and queries. Do not overwrite existing objects:
SHOW XNODES;
CREATE DATABASE taosx_quickstart PRECISION 'ms';
CREATE STABLE taosx_quickstart.temperatures
(ts TIMESTAMP, temperature DOUBLE)
TAGS (device VARCHAR(32));
DESCRIBE taosx_quickstart.temperatures;
Confirm at least one Xnode is online and the supertable contains ts TIMESTAMP, temperature DOUBLE, and tag device VARCHAR(32). If table creation fails, resolve permissions or object conflicts before creating a collection task.
If a proxy is needed, first bring taosX-Agent online following Agent deployment and maintenance, then check Kafka connectivity from the proxy host. The optional Docker environment in this section uses loopback addresses and cannot be used unchanged with a remote proxy.
1.1 Prepare a test Kafka environment with Docker (optional)
If Kafka already exists, skip this section and use the addresses, topic, and authentication supplied by the Kafka administrator. This section prepares a single-node, unauthenticated Kafka only for isolated practice, not production deployment. taosX and Docker must run on the same host. If taosX runs on another host or in a container, these loopback addresses cannot be used unchanged.
- Linux
- Windows
Run the commands below in Bash on the Linux host running taosX. Docker Engine must be running and the execution account authorized to use Docker. If elevation is needed, follow organizational policy; do not bypass authorization by changing Docker socket permissions.
docker version
Run the commands below in Windows PowerShell with Docker Desktop running. taosX runs on this Windows host, not in a Docker container or WSL.
docker version
docker version must return both Client and Server information. If it returns only Client information or cannot connect to the Docker service, resolve the Docker environment first.
Confirm that container name taosx-kafka-demo and host port 19092 are unused, then run these commands in order. Each command is one complete line and works in PowerShell and Bash:
docker pull apache/kafka:3.9.1
docker run -d --name taosx-kafka-demo -p 127.0.0.1:19092:9092 -e KAFKA_NODE_ID=1 -e KAFKA_PROCESS_ROLES=broker,controller -e KAFKA_LISTENERS=HOST://:9092,INTERNAL://:29092,CONTROLLER://:9093 -e KAFKA_ADVERTISED_LISTENERS=HOST://localhost:19092,INTERNAL://localhost:29092 -e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=HOST:PLAINTEXT,INTERNAL:PLAINTEXT,CONTROLLER:PLAINTEXT -e KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL -e KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER -e KAFKA_CONTROLLER_QUORUM_VOTERS=1@localhost:9093 -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 -e KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 -e KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 -e KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 apache/kafka:3.9.1
docker logs --tail 30 taosx-kafka-demo
docker exec taosx-kafka-demo /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:29092 --create --topic taosx_quickstart --partitions 1 --replication-factor 1
docker exec taosx-kafka-demo /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:29092 --describe --topic taosx_quickstart
Wait for logs to confirm Kafka startup before creating the topic. If it is not ready, inspect logs and retry creation. The last command must show topic taosx_quickstart, one partition, and one replica. If the topic already exists, do not delete it or assume it has no historical messages. First check whether this is a retained practice environment. If image pulling fails, check network access or use an organization-approved registry. Do not disable TLS verification.
taosX uses localhost:19092; the producer inside the container below uses localhost:29092. These addresses belong to different runtime layers and are not interchangeable. The exposed port binds only to the Docker host's 127.0.0.1, without authentication or a volume for long-term data storage. After the exercise, stop the ingestion task first, then stop the container with docker stop taosx-kafka-demo. To retain progress, do not delete the container, consumer group, or target database.
2. Minimal configuration and startup
On the Data Ingestion page, click Create New Task and configure the following in order:
- Set the name to
quickstart_kafka, select Kafka as the type, and selecttaosx_quickstartas the target database. - Enter the actual bootstrap-server. If taosX runs on the same host as the Docker environment above, enter
localhost:19092. If Kafka requires SASL or SSL, use the settings provided by the Kafka administrator. Do not disable source authentication to pass the check. - Set the topic to
taosx_quickstart, client ID toquickstart_client_01, and consumer group to a new name dedicated to this test, such asquickstart_kafka_01. Explicitly selectEarliestfor Offset. Click Check Connectivity. - Enter the following sample as the message body in Payload Transformation.
tsis a millisecond timestamp and must fall within target database retention. If changing it, also update both messages and the queries below, keeping the second message1000milliseconds later than the first. After configuring the sample, send the actual message in step 7.
{"device":"d001","ts":1795132800000,"temperature":23.5}
- Select
jsonand check that the parsing preview producesdevice,ts, andtemperature, then select target supertabletemperatures. The table selector may be unavailable until parsing succeeds. Do not add extraction, splitting, or filtering rules in this example. Set the child table name template tot_{device}. Maptsto the timestamp column in milliseconds,temperatureto theDOUBLEcolumn of the same name, anddeviceto the tag of the same name. The mapping preview should showt_d001,23.5, andd001. For a screenshot of the completed configuration, see the Kafka ingestion guide. - Click Submit, return to the list, and confirm that the task has started. If not, select this task and start it manually.
- Send an actual message to the test topic. Use the command below for the Docker exercise. For existing Kafka, use an authorized producer with the corresponding authentication settings.
With this page's Docker environment, send the first message on the Docker host without installing separate Kafka command-line tools:
- Linux
- Windows
printf '%s\n' '{"device":"d001","ts":1795132800000,"temperature":23.5}' | docker exec -i taosx-kafka-demo /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:29092 --topic taosx_quickstart
'{"device":"d001","ts":1795132800000,"temperature":23.5}' | docker exec -i taosx-kafka-demo /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:29092 --topic taosx_quickstart
If the command fails, resolve container, topic, or connection issues first. Even without an error, confirm ingestion with the target queries below. For existing Kafka, use a producer with write permission to send the same message to the selected test topic with that environment's authentication settings. Do not use Docker-internal addresses.
3. Configuration that must be explicit in this example
This example explicitly selects Earliest and uses a new consumer group so that existing group positions do not affect the first read. Kafka addresses, topic, authentication, target database, and mapping must match the actual environment. Do not rely on unchecked advanced-option defaults.
1795132800000 corresponds to UTC 2026-11-20T00:00:00Z. If changing the test time, use the same millisecond timestamps in messages, mapping previews, and query conditions. For complete connection and authentication instructions, see Kafka.
Explicit client IDs and consumer group names are saved unchanged; no prefix or task identifier is forcibly appended. When troubleshooting partition assignment, still use the group name actually saved for the task and query it as described in Consumer group positions and lag. Client IDs do not determine partition assignment within a group.
4. Verification
Run in the taosExplorer Data Browser or taos CLI:
SELECT ts, temperature, device
FROM taosx_quickstart.t_d001
WHERE ts = 1795132800000;
Expect one row: temperature is 23.5, tag device is d001, and the timestamp matches the test message. taos CLI may display time in its host's time zone. Use the millisecond timestamp condition to check the same instant.
Send another message with a timestamp 1000 milliseconds later and temperature 24.5, and confirm that the second row can be queried. These two messages verify the initial write and continuous consumption. Resending a message with the same timestamp does not necessarily increase the target row count. Row count alone cannot determine whether a message was received.
Send the second message on the same Docker host. Its timestamp is 1000 milliseconds later than the first and its temperature is 24.5, to verify continuous consumption:
- Linux
- Windows
printf '%s\n' '{"device":"d001","ts":1795132801000,"temperature":24.5}' | docker exec -i taosx-kafka-demo /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:29092 --topic taosx_quickstart
'{"device":"d001","ts":1795132801000,"temperature":24.5}' | docker exec -i taosx-kafka-demo /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:29092 --topic taosx_quickstart
Query both test timestamps in the taosExplorer Data Browser or taos CLI. Expect two rows with temperatures 23.5 and 24.5, both tagged d001:
SELECT ts, temperature, device
FROM taosx_quickstart.t_d001
WHERE ts IN (1795132800000, 1795132801000)
ORDER BY ts;
Verification is complete when the second message is written successfully. If either query differs from expectations, start with No data on first ingestion. For full configuration and limitations, see Kafka. For stopping and recovery, see Restarts, checkpoints, and store-and-forward. For other symptoms, see Troubleshooting by symptom.