After configuring the change tracking channel, you can use the SDK sample code provided by DTS to track data changes. This topic describes how to use the sample code.

Prerequisites

A change tracking task is created. For more information, see Track data changes from ApsaraDB RDS for MySQL (previous).

Preparations

Create an AccessKey and obtain the AccessKey ID and AccessKey Secret. For more information, see create an AccessKey pair.

Notice If you use a RAM user to subscribe to data, you must have the AliyunDTSFullAccess permission. For more information , see Authorize a RAM user to use DTS.

Procedure

This topic uses IntelliJ IDEA (version Community Edition 2018.1.4 Windows) as an example to describe how to run the SDK to consume tracked data.

  1. Download SDK sample code files, and then decompress the file.
  2. Optional:Locate to the directory where you extracted the SDK sample code, and use text editing tools to open the pom.xml, then change the SDK version to the latest.
    Set SDK versions
    Notice You can obtain the latest data subscription SDK version from Maven. For more information, see Maven page of the change tracking SDK.
  3. Open IntelliJ IDEA. In the window that appears, click Open.
    Open a project
  4. In the dialog box that appears, locate the directory where the SDK sample code is decompressed, expand the folders, and locate the project object model File: pom.xml.
    Locate the project object model file
  5. In the dialog box that appears, select Open as Project.
  6. On the IntelliJ IDEA page, double-click the target file: Main.java.
    Open the java client of the apsaradb RDS for MySQL instance.
  7. Set the parameters in the Java client file.
    Set parameters
    Parameter Description
    accessKey Enter the AccessKey ID and AccessKey Secret of the Alibaba cloud account. For more information, see Preparations.
    accessSecret
    subscribeInstanceID The ID of the target instance. You can log in DTS console. In the left-side navigation pane, click Change Tracking Tasks and find the target instance ID.
  8. On the top of the IntelliJ IDEA page, choose Run > Run to run the client.
    Note On the first run, the software loads and installs the relevant dependency package.

Result

The following figure shows that the Kafka client can track data changes in the source database.

SDK demo running results