You can use the SDK sample code provided by DTS to consume tracked data. This topic describes the interface definitions of main classes in the SDK.

Download SDK demo code

For more information, see Download SDK.

Interface definitions of the RegionContex class

Interface functions Description
setAccessKey(AccessKey) Configure the AccessKey ID of the Alibaba Cloud account to which the target instance belongs.
setSecret(AccessKeySecret) Configure the AccessKey Secret of the Alibaba Cloud account to which the target instance belongs.
setUsePublicIp(usePublicIp) Configure whether to use the public network to subscribe to data.
Note Currently, you can subscribe to data only through the public network.
context.setUseBinary(boolean useBinary) Configure whether to enable binary mode to compose data packets. Valid values: True and False. We recommend that you enable this method (set it to True) to improve consumption performance.
context.setUseDrcNet(boolean useDrcNet) Configure whether to enable the network optimization feature. Valid values: True and False. We recommend that you enable this feature (set it to True) to improve consumption performance.

Interface definitions of the ClusterClient class

Interface functions Description
void addConcurrentListener(ClusterListener arg0) Add a Listener to get incremental data from the subscription channel.
Note The parameter ClusterListener arg0 is an object of class ClusterListener.
void askForGUID(String arg0) The ID of the change tracking instance. You can specify this parameter to obtain the incremental data in the change tracking channel.
List<ClusterListener> getConcurrentListeners() Gets the list of listeners in the ClusterClient. The return type of the interface is List <ClusterListener>.
void start() Starts the SDK client to subscribe to incremental data.
void stop() Stops the SDK client to stop subscribing to incremental data.
Note The same thread is used to pull data and callback The notify function. Therefore, when the consumption code of the notify function contains a function that cannot be interrupted, the stop function may fail to properly close the SDK client.

Interface definitions of the ClusterListener class

void notify(List<ClusterMessage> arg0): it defines the consumption method of subscribed data. When the SDK receives the data, it notifies ClusterListner through The notify function to consume the data, and then prints the subscription data to the screen.

Interface definitions of the ClusterMessage class

Note Each ClusterMessage message stores the data Record of a transaction. Each Record in the transaction is stored using a Record.
Interface functions Description
Record getRecord() Obtain a change record from the ClusterMessage object. This record contains the specific records in the Binlog file, such as begin, commit, update, and insert operations.
void ackAsConsumed After the consumption is completed, you need to call this operation to report an ACK (confirmation message) to DTS and notify the server of updating the consumption checkpoint to ensure data integrity after SDK restart.
Note When the SDK client stops responding and restarts, it automatically subscribes to and consumes data from the last consumption checkpoint that is recorded before.

Interface definitions of the Record class

String getAttribute(String key): it obtain the property values of the Record. You can pass in the parameters in the following table when calling this function to obtain the corresponding attribute value.
Parameter Description
record_id The ID of the record.
Note The ID is not necessarily incremental during the subscription process.
instance The endpoint of the instance, in the format of IP:Port.
source_type The engine type of the database. Fixed value: MySQL.
source_category The type of the DNS record. Fixed value: full_recorded.
timestamp The Binlog timestamp when the SQL statements was run in the source database.
checkpoint The checkpoint of the Binlog. The format is: binlog_offset @ binlog_file.
Note binlog_offset is the offset of this record in the binlog file, binlog_file is the numerical suffix of the binlog file. For example, if the binlog file name is mysql-bin.0008, the binlog_file is 8.
record_type The type of the operation. Valid values: insert, update, delete, replace, ddl, begin, commit, and heartbeat.
Note The heartbeat is the table defined by DTS. DTS generates one heartbeat record per second to detect whether the subscription channel is operating normally.
db The name of the database.
table_name The name of the table.
record_recording The encoding format.
primary The name of the primary key column. If the primary key is a composite key, the names of the columns are separated by commas (,).
fields_enc The encoding of the field value. Separate multiple fields with commas (,).
Note If the field value is not of the character type, the value is null.

The following table lists the preset interface functions of the SDK to get the property values in Record.

Interface functions Description
Type getOpt() Obtains the operation type.
String getCheckpoint() Obtains the Binlog offset.
String gettimestamp() Obtains the timestamp of a Binlog file.
String getDbname() Obtains the database name.
String getTablename() Obtain the table name.
String getPrimaryKeys() Obtain the primary key column name.
DBType getDbType() Obtains the database type.
String getServerId() Obtain the endpoint of the RDS instance.
int getFieldCount() Obtains the number of fields.
List<Field> getFieldList() Obtain the definitions of all fields, pre-change, and post-change image values. For more information about the Field object definition, see Interface definitions of the Field class.
Boolean isFirstInLogevent() Determines whether the record is the first transaction log record in a large volume change Database. The return value is True or False.

Interface definitions of the Field class

Interface functions Description
String getEncoding() Obtains the encoding format of the field value.
String getFieldname() Obtains the name of the field.
Type getType() Obtains the data Type of the field.
ByteString getValue() Obtains the value of this field. The return type is ByteString. If the field is not specified, the return value NULL.
Boolean isPrimary() Determines whether the field is a primary key column. Return value: True or False.