Skip to main content

Publish to Kafka

info

Kafka publishing sends TDengine subscription data and selected metadata to Kafka for downstream consumption. Verify message content at the consumer. This link runs in the opposite direction to Kafka ingestion. Successful SASL authentication does not establish write permissions.

Where to operate: taosExplorer → Data Publishing → Kafka, or taosx run on the command line. Prepare the source in the taosExplorer Data Browser or taos CLI and verify downstream in a Kafka consumer client.

Data flows TDengine TMQ → taosX → Kafka, opposite to Kafka ingestion. Here taosX is a Kafka producer. The source consumer group is a TDengine TMQ group, not the downstream Kafka consumer group.

1. Prepare a Minimal Link​

ItemMaterials and conditions
TDengine sourcetaosd, taosAdapter, a usable topic, subscription identity, and retention scope. Use isolated test objects initially.
taosXThe delivered version is confirmed to support Kafka publishing. The actual command or service execution host can reach source taosAdapter and Kafka.
Kafka targetBroker list, precreated Topic, publish ACL, and security materials. Returned cluster addresses are also reachable.
Downstream verificationKafka client and consume permissions on an isolated test Topic. Begin consumption before writing source data.
Permission boundariesDo not enable anonymous access or automatic Topic management for convenient production testing. GSSAPI tools must be available in the actual execution environment.

In an isolated test environment, have an authorized TDengine TSDB administrator run the following SQL in the taosExplorer Data Browser or taos CLI. If the database name exists, use a new name and update subsequent topics and queries consistently. Do not overwrite business databases.

CREATE DATABASE taosx_out_demo PRECISION 'ms' WAL_RETENTION_PERIOD 86400;
CREATE STABLE taosx_out_demo.meters (ts TIMESTAMP, value DOUBLE)
TAGS (site VARCHAR(16));
CREATE TABLE taosx_out_demo.meter_1 USING taosx_out_demo.meters TAGS ('lab');

Create source objects and topics first, then prepare consumers for the selected method. Write test data after consumers are ready. Verify historical reads of existing data separately from continuous reads after subscription. Topic creation alone does not establish successful data transfer.

Create a separate source topic for Kafka publishing in the taosExplorer Data Browser or taos CLI:

CREATE TOPIC taosx_out_kafka AS
SELECT ts, tbname, value, site FROM taosx_out_demo.meters;

Have the Kafka administrator precreate a dedicated target Topic such as taosx.test.meters and provide Brokers, authentication, TLS, and write permissions. Disable automatic Topic creation initially to avoid expanding the test into Broker administration changes. The actual taosX host must reach initial Brokers and cluster addresses they return.

On the verification host, use an installed Kafka client to read the dedicated Topic, for example in Linux Bash:

bin/kafka-console-consumer.sh --bootstrap-server <Kafka主机>:9092 --topic taosx.test.meters --from-beginning

On Windows, use the corresponding Kafka client command or run in a Docker/WSL client environment. Set container addresses according to the client's environment. Pass production authentication through the administrator-provided client configuration file; do not disable SASL or TLS for verification.

2. Minimal GUI Publishing​

Open Data Publishing in the left navigation and click Create New Task, then select Kafka. Enter a task name identifying source, purpose, and environment. Do not open Data In → Kafka, which is the opposite direction.

Kafka publishing task name and target type

  1. Add a Kafka data publishing task, enter the source TMQ DSN, and select data subscription. Explicitly set the first starting position to Earliest and use a dedicated fixed group name.
  2. Enter target Kafka Brokers, authentication, and TLS. For SASL, configure the administrator-specified mechanism. GSSAPI also requires service name, principal, initialization command, and keytab.
  3. Set Data Topic to taosx.test.meters. Initially use no templates or custom Keys, and disable metadata subscription and automatic Topic creation.
  4. Run connectivity checks and preview. Check target Topic, message Key, and body.
  5. Submit and start the task, then write source test data and verify downstream messages.
note

GSSAPI tools and keytab must be available in the actual task execution environment. Restrict access to certificates, private keys, and sensitive files. Browser file upload does not establish a configured Kerberos environment.

2.1 Enter Source Subscription and Switches​

In Topic DSN, enter the reachable source taosAdapter address and taosx_out_kafka created above. This example explicitly selects earliest, a fixed consumer group, data subscription enabled, and metadata subscription disabled. Record the actual saved group name, not only the task name on the page.

Kafka publishing source TMQ address, start, group, and event switches

GUI optionSource DSN parameterInput and applicability
Starting Positionauto.offset.resetearliest or latest. Switching start does not force replacement of existing committed progress.
Consumer Group IDgroup.idFix a dedicated group for this task, not shared with other downstream systems.
Enable Data Subscriptionwith.dataInitially enabled in a new form; retained here. Data and metadata cannot both be disabled.
Enable Metadata Subscriptionwith.metaInitially disabled in a new form. Enable only when the source topic supplies required events and downstream can handle them.
TSDB Dataexperimental.snapshot.enableInitially enabled in a new form; affects persisted-data reads. It cannot recover data outside source retention.
Table Deletionswith.meta.dropInitially enabled in the form. Forwarding applies only when metadata subscription and source events satisfy requirements.
Data Deletionswith.meta.deleteInitially enabled in the form. Define how downstream applies deletions before enabling related events.

If the same options appear in both form controls and a manual DSN, check final values before submission and remove conflicting settings. This page uses a query topic for the data exercise. For schema events, prepare a corresponding topic under source subscription rules rather than just switching options.

2.2 Connection and Authentication​

Use ASCII commas between host:port entries in Bootstrap Servers. For unauthenticated tests, leave SASL unselected and SSL off. In production, follow the Broker administrator's security configuration; do not disable authentication to match the exercise.

Kafka publishing Broker list and authentication entry points

After selecting PLAIN or SCRAM-SHA-256, enter the publishing identity's username and password. Successful SASL authentication does not establish target Topic write permission. Check publish ACLs separately. PLAIN does not replace TLS encryption.

Kafka publishing PLAIN username and password settings

For GSSAPI, prepare the Kerberos service name, principal, initialization command, and keytab separately. Confirm commands under on-site Kerberos policy. Placeholder hints are not complete executable configuration. Required tools, keys, and a reachable KDC belong in the actual taosX execution environment.

Four GSSAPI authentication materials for Kafka publishing

After enabling SSL Authentication, provide the CA, CA password, and required client certificate/private key as directed by the administrator. Check matching files, validity, and readability by the execution identity. The image expands both GSSAPI and SSL to show controls; it does not mean both must be selected. See TLS, DSNs, and Sensitive Files for host, permission, and protection requirements.

warning

The default connection configuration disables TLS endpoint hostname verification. Supplying a CA and enabling SSL does not establish strict Broker identity verification. If security policy requires hostname verification, confirm a compliant delivery and configuration with the security administrator and technical support, then verify with actual Broker certificates. Native extensions can also override security settings. Connectivity success does not replace security verification. ca_password actually supplies the client private-key passphrase, not a general CA-file decryption password.

Kafka publishing TLS file settings

2.3 Configure Routing and Prepare Submission​

A new form prefills Data Topic with taosx.data.out; explicitly change it to approved taosx.test.meters here. Gray examples in Metadata Topic, Data Key, and Metadata Key are not saved values. Leave Keys empty initially and verify fixed-Topic messages first.

Kafka publishing data/metadata Topics, Keys, and automatic Topic creation

After setup, review advanced parameters and preview below, then submit and confirm startup. Creation-form screenshots do not replace downstream verification.

3. Corresponding CLI Examples and Required Parameters​

This isolated test assumes source taosAdapter and unauthenticated Kafka are reachable through the execution host's 127.0.0.1, and the source retains unchanged default root / taosdata credentials. For changed credentials, remote hosts, or production, replace identities, addresses, and security configuration. Do not weaken authentication to copy the example.

taosx run -f 'tmq+ws://root:taosdata@127.0.0.1:6041/taosx_out_kafka?group.id=taosx_out_kafka_demo&auto.offset.reset=earliest&timeout=never&with.data=true&with.meta=false' -t 'kafka://127.0.0.1:9092?data_topic=taosx.test.meters&auto_create_topic=false'

Keep quotes on both DSNs. In containers or WSL, loopback belongs to that runtime environment. Kafka advertised.listeners must return addresses reachable from the actual execution environment; initial-port reachability alone is insufficient.

ParameterMeaning
Source group.idThis publishing task's TMQ consumer group. Do not unintentionally share it with other targets.
Source with.data / with.metaControl data or metadata publishing. They cannot both be disabled and belong in the source DSN.
Target data_topicRequired when data is enabled. CLI does not rely on the GUI's prefilled Topic default.
Target meta_topicMetadata Topic. Falls back to Data Topic if omitted; explicitly required for metadata-only publishing.
data_key / meta_keyMessage Key templates. Omitted meta_key falls back to data_key only when data publishing is also enabled. For a Key in metadata-only mode, explicitly set meta_key.
auto_create_topic=falseDo not automatically create target Topics. Before enabling, confirm Kafka management permissions, partitions, and replicas.

Topic and Key templates can use source database, table, source topic, and other variables. Data and metadata events provide different variables and must be previewed separately. A stable Key helps choose partitions but does not guarantee global order across all source partitions, Topics, and event types.

See Kafka Publishing Parameters for full target parameters and connection/authentication definitions. Configure Kafka identity with query keys such as sasl_username and sasl_password. The user-info segment in kafka://用户:密码@主机 is not SASL configuration for this entry point.

3.1 Routing and Automatic Topic Creation​

Templates can use event-provided variables such as {database}, {tmq_topic}, {vgroup_id}, {table}, and {stable}. Topics can use {offset} when the context provides it. ${...} normalizes to {...}. Do not automatically treat business columns value or site as routing variables. Preview real events first.

Data messages do not automatically provide supertable stable or tag variables. table also depends on the source message carrying a table name. Metadata such as supertable creation may contain only stable, not table; deletion events have their own contexts. Templates with unknown variables or unclosed braces fail. To simplify initial diagnosis, verify fixed Topics first, then add routing and Keys separately for each event type.

With auto_create_topic enabled, auto_create_topic_partitions and auto_create_topic_replication_factor set partitions and replicas and must be positive. Replicas are also limited by available Brokers and cluster policy. If omitted, Kafka handles defaults. Do not copy form ranges or prefilled values into a taosx run target DSN. In production, Kafka administrators normally precreate and review topics.

The GUI shows Topic Partitions and Replication Factor only after Automatically Create Topic is enabled. Both start empty. Allowed form ranges are 1–1024 and 1–128 respectively. These are UI input constraints, not proof of current Kafka capacity or a replacement for checking taosx run commands and Brokers.

Partition count and replication factor shown after enabling automatic Topic creation

3.2 Producer Parameters and Units​

The following defaults are for direct target DSNs, not taosExplorer form-prefilled values. When creating in the GUI, check the actual saved configuration.

Kafka publishing form concurrency, queue wait, batch, and extension parameters

A new GUI form starts with concurrency 1, queue timeout 30000 milliseconds, batch size 1000, and batch timeout 1000 milliseconds. Record these separately from direct DSN defaults below. Direct DSNs bypass the form, so screenshots do not determine omitted-parameter behavior. In Kafka Extension Parameters, enter key and value separately, such as key compression.type, value zstd. Do not prefix GUI keys with kafka..

Target DSN parameterDirect DSN defaultMeaning
concurrencyAvailable logical parallelism, or 5 if retrieval failsPublishing concurrency; neither source partition count nor a fixed 1 at every entry point.
queue_timeout2sEnqueue-attempt wait budget when the Producer queue is full, not a universal Kafka delivery timeout for all messages.
batch_size1000Publishing-batch message count, not byte size.
batch_timeout5sPublishing-batch wait setting, distinct from full-queue waiting.
auto_create_topicfalseWhether to attempt target Topic creation.
kafka.原生参数名UnsetNative Producer extension configuration; kafka. is stripped before passing it to the Kafka client.

Durations support units such as 500ms and 2s. Bare integers are milliseconds. Always include units to avoid reading 5 as 5 seconds. Source DSN recv_timeout defaults to 5s; it is TMQ receive waiting, not a target Producer timeout.

concurrency caps work units per source topic, with actual concurrency no higher than that topic's vgroup count. Multiple source topics are calculated separately. It cannot directly predict total task connections or target Kafka partitions. 0 is treated as 1, not automatic expansion to all source partitions.

batch_size is a send trigger, not a strict batch cap. One source data block can contain multiple messages, taking the current batch over the threshold. A nonempty batch also triggers when its wait expires. batch_timeout=0 is not infinite waiting. Initially choose few messages and a short wait explicitly, verify, then tune for throughput and delay.

These publishing wait parameters do not accept 1m or 1.5s. Read-side batch_timeout millisecond-only values and TAOSX_KAFKA_BATCH_TIMEOUT_MS override rules do not apply here. One TMQ receive wait ending does not mean the task should exit. Shortening recv_timeout cannot establish that all publishing is complete.

For example, add &kafka.compression.type=zstd&kafka.acks=all&kafka.linger.ms=100 to the target DSN. Native parameters use Kafka client's own units, not uniform conversion under the taosX time rules above. Check conflicts, throughput, and delivery semantics separately. acks=all still does not provide atomic transactions across TMQ and Kafka.

Publishing collects native extensions only from target DSN keys prefixed with kafka.. It does not read ingestion-side KAFKA_CONSUMER_EXTRAS as the same entry point or accept bare compression.type as equivalent. Extensions apply after connection configuration and can override Brokers, security protocols, hostname verification, and other settings. Inspect final configuration and sensitive information first. Do not change security options arbitrarily to finish testing.

3.3 Save and Preview Checks​

Before submission, check source DSN and start, ensure data/metadata are not both disabled, and check target Topics required by enabled directions, authentication materials, and actual permissions. Connection checks do not establish downstream parsing. Preview count and wait control sampling only, not production batches or timeouts. Inspect returned topic, key, and value individually for routing and envelope. If no samples appear after waiting, first check readable source records and preview start, not a full scan.

Under Connectivity Check, click Check Connectivity to check source TMQ and target Kafka. Fix addresses, security materials, and permissions on failure rather than repeatedly submitting or expanding source scope.

Source and target connectivity check for Kafka publishing

Under Preview, set Record Count and Wait Time. A new form starts at 1 record and 30 seconds; ranges are 1–100 records and 1–300 seconds. Preview returns when either condition is reached; it need not wait the full time. Click Preview Data, then check topic, key, and value in the result area. With no sample, retain the message and investigate new source data, group positions, and start. Messages may contain business data; do not put unredacted previews directly into tickets.

Kafka publishing preview record count and wait time

After connectivity and configuration checks pass, click Submit. In the list, find the task by name and confirm saved settings, actual group, and runtime status. Start the original task if needed. Then write new source data and verify the target Topic. A single preview does not prove continuous publishing.

4. Verify Envelope and Business Values​

Run in the source cluster's taosExplorer Data Browser or taos CLI:

INSERT INTO taosx_out_demo.meter_1 VALUES (NOW, 23.5);
SELECT ts, value, site FROM taosx_out_demo.meter_1 ORDER BY ts;

Record the actual timestamp. Find the corresponding Kafka data message: type is data, context includes source database, source topic, vgroup, and position, and data.columns contains the projected business fields. Check time, 23.5, meter_1, and lab, then write another timestamp to confirm continuous publishing.

The data envelope for this example is as follows. Timestamps and positions are illustrative; compare against actual source-query results rather than expecting identical numbers:

{
"type": "data",
"context": {
"database": "taosx_out_demo",
"topic": "taosx_out_kafka",
"vgroupId": 2,
"offset": 7
},
"data": {
"columns": {
"ts": 1704067200000,
"tbname": "meter_1",
"value": 23.5,
"site": "lab"
}
}
}

data.columns.tbname and site come from this source topic's explicit projection. Do not expect every message to additionally contain data.table, data.stable, or data.tags. Compare the example's millisecond timestamps with source queries at the same precision. context.offset is a source TMQ position, not a Kafka message position. Historical snapshots can have negative values; negativity alone does not establish failure.

Metadata messages have type set to meta and contain events and their contents, not this example's column-data message. Downstream must follow the actual message contract, not directly reuse MQTT's data/offset parser.

5. Troubleshooting​

SymptomNext action
Connectivity failsFrom the taosX host, check returned Broker addresses, SASL, certificates, and write ACLs.
Topic missingConfirm the actual target name. Have the administrator create it, or configure authorized automatic creation. Do not broaden permissions by default.
Data arrives but metadata does notCheck source topic metadata coverage, source switches, and a separate metadata Topic.
Preview works but downstream has no messagesCheck task startup, new source data, TMQ group positions, actual target Topic, and downstream subscription configuration.
Messages arrive but business processing failsCompare envelope, field types, Keys, and downstream logs, not only Kafka consumption counts.
render Kafka topic or key template failedCheck the specific unknown variable or brace error. Verify fixed Topic/Key first, then data and each metadata type separately. Not every event has table or stable.
failed to enqueue Kafka message or failed to deliver Kafka messageDistinguish Producer enqueue failure from Broker delivery failure. Save the complete client error and check actual Topic, size, ACLs, queues, and client delivery settings. Do not only increase queue_timeout.
failed to commit TMQ offset after Kafka deliveryThis batch may already be in Kafka. Retain the original source topic/group, inspect positions and downstream business records, and check replay after repairing the source connection. Do not change groups or clear the target first.

Retrieve actual logs through Logs and Performance. See TMQ Continuous Synchronization for source-position queries. If monitoring has no samples for this task, first check reporting destination and run start.

For other task, write, and runtime issues, see Troubleshooting by Symptom.

6. Stop and Resume​

Stop and restart the original service task in the list; use Ctrl+C for foreground CLI. Retain the source topic and group name. After recovery, verify every source partition and downstream business records. Publishing commits corresponding TMQ positions after successful Kafka delivery, but these are not a cross-system transaction. Failure before commit can cause replay. Do not promise end-to-end exactly-once behavior.

This publishing path forcibly disables TMQ source automatic commits, then commits corresponding positions after Kafka delivery completes. Do not try to change this agreement with enable.auto.commit=true, or apply ordinary synchronization commit-batch options. Downstream business processing still needs its own idempotency rules. Target publishing configuration cannot recover gaps caused by insufficient source retention.

7. Limitations​

Published envelopes do not replace original TDengine backups. Reconstructing a target from metadata messages depends on downstream implementation and supported events. Enabling publishing does not guarantee whole-database recovery. Before large-scale publishing, validate downstream throughput, Topic planning, and source retention.