docs/en/06-advanced/01-subscription/02-native.md
TDengine TSDB provides data subscription and consumption interfaces similar to those of message queue systems. In many scenarios, using TDengine TSDB as the time-series data platform eliminates the need to integrate an additional message queue, thereby simplifying application design and reducing operational costs.
For fundamental concepts such as topic management, refer to the documentation. For detailed API usage, see the Developer Guide.
The following SQL statement creates a subscription named topic_meters. Each record retrieved from this subscription will contain the columns selected by the query SELECT ts, current, voltage, phase, groupid, location FROM meters.
CREATE TOPIC IF NOT EXISTS topic_meters AS SELECT ts, current, voltage, phase, groupid, location FROM meters;
The concept of a consumer in TDengine TSDB is similar to Kafka: consumers receive data streams by subscribing to topics. Consumers can be configured with various parameters, such as connection method, server address, auto-commit offsets, auto-reconnect, and data compression.
The key parameters for creating a consumer include:
After a consumer subscribes to one or more topics, it can begin receiving and processing messages from those topics.
The typical workflow is as follows:
A consumer can specify an offset to start reading messages from a particular position within a partition. This allows the consumer to re-read previously processed messages or skip those that have already been handled.
After a consumer has successfully read and processed messages, it can commit the offset to record its progress. A committed offset indicates that all messages up to that position have been processed successfully. Offset commits can be performed either automatically (at regular intervals based on configuration) or manually (controlled by the application).
A consumer can unsubscribe from topics to stop receiving messages. When a consumer is no longer needed, it should be closed to release resources and disconnect from the TDengine TSDB server.