You can use the SDK demo code that is provided by DTS to consume tracked data. This topic describes the methods that are available for the SDK classes.
Download the SDK demo code
For more information, visit Download SDK.
Methods of the RegionContex class
Method | Description |
---|---|
setAccessKey(accessKey) |
Specifies the AccessKey ID of the Alibaba Cloud account to which the source instance belongs. |
setSecret(AccessKeySecret) |
Specifies the AccessKey secret of the Alibaba Cloud account to which the source instance belongs. |
setUsePublicIp(usePublicIp) |
Specifies whether to track data changes over the Internet.
Note DTS can track data changes only over the Internet. Therefore, set the usePublicIp
parameter to
true .
|
context.setUseBinary(boolean useBinary) |
Specifies whether to enable the binary packaging feature. Valid values: True and False. We recommend that you enable this feature to improve consumption performance. |
context.setUseDrcNet(boolean useDrcNet) |
Specifies whether to enable the network optimization feature. Valid values: True and False. We recommend that you enable this feature to improve consumption performance. |
Methods of the ClusterClient class
Method | Description |
---|---|
void addConcurrentListener(ClusterListener arg0) |
Adds a downstream listener to retrieve data changes from a change tracking channel.
Note The
ClusterListener arg0 parameter specifies an object of the ClusterListener class.
|
void askForGUID(String arg0) |
Retrieves data changes from a change tracking channel. Set the String arg0 parameter to the ID of the change tracking instance. |
List<ClusterListener> getConcurrentListeners() |
Queries the list of listeners in a ClusterClient object. The return type is List <ClusterListener> .
|
void start() |
Starts the SDK client to start change tracking. |
void stop() |
Stops the SDK client to stop change tracking.
Note Data pulling and notification callback are performed in the same thread of the SDK
client. If the consumption code of the notify() method contains a function that prevents
signal interruptions, the stop() function may fail to terminate the SDK client.
|
Method of the ClusterListener class
The void notify(List<ClusterMessage> arg0)
method specifies the consumption mode of tracked data. When the DTS SDK receives
the data, it uses the notify() function to notify a ClusterListener object to consume
the data. Then, the SDK displays the data on the screen.
Methods of the ClusterMessage class
Method | Description |
---|---|
Record getRecord() |
Retrieves a change record from a ClusterMessage object. The change record contains an entry in the binary log file, such as a BEGIN, COMMIT, UPDATE, or INSERT operation. |
void ackAsConsumed |
After the data consumption is complete, you must call this method to send an ACK packet
to instruct the DTS server to update the consumer offset. This ensures the integrity
of the consumed data after an abnormal SDK client restarts.
Note If a downstream SDK client restarts after a breakdown, the client resumes change tracking
from the last consumer offset.
|
Methods of the Record class
TheString getAttribute(String key)
method retrieves the attribute values in a Record object. The following table describes
the parameters that are available when you call this method.
Parameter | Description |
---|---|
record_id |
The ID of the record.
Note The record ID may not increment during the change tracking process.
|
instance |
The endpoint that is used to connect to the database instance. The format is <IP address>:<Port number>. |
source_type |
The engine type of the database instance. The value is set to MySQL. |
source_category |
The type of the record. The value is set to full_recorded. |
timestamp |
The binlog timestamp that is generated when the SQL statement is executed in the source database. |
checkpoint |
The checkpoint of the binary log file. The format is binlog_offset@binlog_file .
Note The
binlog_offset parameter indicates the offset of a record in the binary log file. The binlog_file parameter indicates the numerical suffix of the binary log file. For example, if
the name of a binary log file is mysql-bin.0008, the value of the binlog_file parameter
is 8.
|
record_type |
The operation type. Valid values: insert, update, delete, replace, ddl, begin, commit,
and heartbeat.
Note A heartbeat record indicates the heartbeat table that is defined by DTS. The system
generates one heartbeat record per second to detect whether the change tracking channel
is running as expected.
|
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, separate column names with commas (,). |
fields_enc |
The encoding of each field value. Separate fields with commas (,).
Note If a field value is not of the character type, the encoding of this field value is
null.
|
The following table lists the methods that are preset in the SDK demo code. You can call these methods to retrieve the attribute values in a Record object.
Method | Description |
---|---|
Type getOpt() |
Queries the operation type. |
String getCheckpoint() |
Queries the checkpoint of the binary log file. |
String gettimestamp() |
Queries the timestamp of the binary log file. |
String getDbname() |
Queries the database name. |
String getTablename() |
Queries the table name. |
String getPrimaryKeys() |
Queries the name of the primary key column. |
DBType getDbType() |
Queries the database type. |
String getServerId() |
Queries the endpoint that is used to connect to the database instance. |
int getFieldCount() |
Queries the number of fields. |
List<Field> getFieldList() |
Queries the definitions of all fields, the pre-change image values, and the post-change image values. For more information, see Methods of the Field class. |
Boolean isFirstInLogevent() |
Checks whether the record is the first transaction log in a large volume of data changes. The return value is True or False. |
Methods of the Field class
Method | Description |
---|---|
String getEncoding() |
Queries the encoding format of the field value. |
String getFieldname() |
Queries the name of the field. |
Type getType() |
Queries the data type of the field. |
ByteString getValue() |
Queries the value of the field. The return type is ByteString. If the field is not
specified, the method returns NULL .
|
Boolean isPrimary() |
Checks whether the field is a primary key column. The return value is True or False. |