These programs are part of the main github.com/apache/iotdb-client-go/v2 module. They demonstrate the Go subscription client with Pull and Push consumers, manual commit, progress, Seek, and processors.
Run the commands from the example/ directory with Go 1.25 or later and a subscription-enabled IoTDB server.
| Program | Scenario | APIs demonstrated |
|---|---|---|
| tree | Tree path/time filtering and topic management | Session management, Pull/Push record consumption, automatic commit |
| table | Table database/table/time filtering and schema metadata | Session management, Pull/Push record consumption, automatic commit |
| tree/incremental | Tree incremental records with checkpoint recovery | Manual commit, progress, SeekAfter, optional processors |
| table/incremental | Table incremental records with checkpoint recovery | Manual commit, progress, SeekAfter, optional processors |
import (
"github.com/apache/iotdb-client-go/v2/subscription"
subconsumer "github.com/apache/iotdb-client-go/v2/subscription/consumer"
subpayload "github.com/apache/iotdb-client-go/v2/subscription/payload"
subprocessor "github.com/apache/iotdb-client-go/v2/subscription/processor"
subsession "github.com/apache/iotdb-client-go/v2/subscription/session"
)
The root subscription package contains shared model constants, connection configuration, and public errors. Management uses subsession, consumption uses subconsumer, record values use subpayload, and processors use subprocessor.
The ordinary programs create sample data and a SubscriptionRecordHandler topic, subscribe, consume records, and print topic/subscription metadata.
cd example go run ./subscription/tree go run ./subscription/table
Pull is the default consumer mode and uses automatic commit. Process a delivered batch according to application requirements; automatic commit confirms it after the configured interval.
Push delivery runs on the consumer background loop and invokes a sequential callback:
go run ./subscription/tree -consumer=push -ack=after -duration=10s go run ./subscription/table -consumer=push -ack=before -duration=10s
-ack=after acknowledges successful callbacks and nacks failed callbacks.-ack=before acknowledges the batch before invoking callbacks.The incremental programs create a bootstrap record before subscribing, then write new records through the incremental path. They use PollWithInfo, manual commit, Positions, CommittedPositions, and SeekAfter.
go run ./subscription/tree/incremental go run ./subscription/table/incremental
The checkpoint is kept in memory for the current run; the programs do not persist it to disk.
Enable the optional processor chain with -processors:
go run ./subscription/tree/incremental -processors go run ./subscription/table/incremental -processors
The chain installs WatermarkProcessor and the model-specific ColumnAlignProcessor. It demonstrates message-level watermark ordering and in-place column alignment.
The programs accept -host, -port, and -username, defaulting to 127.0.0.1:6667 and root. IOTDB_PASSWORD supplies the password and defaults to root when unset.
IOTDB_PASSWORD='your-password' go run ./subscription/table \ -host=127.0.0.1 \ -port=6667 \ -username=root
Each run uses unique resource names. The programs:
subscription.ErrUnsupportedTsFile.See the subscription client guide for configuration defaults, message ownership, errors, and the complete public API.