Database/Table Data Subscription to Local File System

Last updated: 2020-04-27 17:04:09

    This document provides a simple example that walks you through how to pull a table from data subscription to a local file system as well as a simple Local Demo. The following operations are performed on CentOS.

    Configuring Environment

    Getting Key

    Log in to the CAM Console to get a key.

    Selecting Data Subscription

    1. Log in to the DTS Console and select Data Subscription on the left sidebar to enter the data subscription page.

    2. Select the name of the TencentDB instance to be synced, click "Start", return to the data subscription page, and click the data subscription you created. For detailed directions, please see How to Get a Data Subscription.

    3. Check the corresponding DTS channel, IP, and port and enter them together with the obtained key into the corresponding

      // // Enter the key obtained from TencentCloud API here
           context.setSecretId("AKIDfdsfdsfsdt1331431sdfds"); Enter the `secretID` obtained from TencentCloud API
           context.setSecretKey("test111usdfsdfsddsfRkeT"); Enter
           the `secretKey` obtained from TencentCloud API
       // Enter the IP and port obtained through data subscription in the DTS service here
           context.setServiceIp(""); Enter the IP obtained from the data subscription configuration
           Enter the port obtained from the data subscription configuration
           final DefaultSubscribeClient client = new DefaultSubscribeClient(context);
       // Enter the names of both the database and table to be synced and modify the name of the file where they will be stored
           final String targetDatabase = "test"; Enter the name of the database to subscribe to
           final String targetTable = "alantest"; Enter the name of the table to subscribe to
           final String fileName = "test.alan.txt"; Enter the name of the local file for storage
       // Enter the `dts-channel` configuration information obtained from the data subscription configuration here
       client.askForGUID("dts-channel-e4FQxtYV3It4test"); Enter the DTS channel name obtained from the data subscription

    Compiling and Testing

    1. [root@VM_71_10_centos ~]# javac -classpath binlogsdk-2.6.0-release.jar -encoding UTF-8
    2. Launch the program. If no errors are reported, the program works properly. Check the previously configured local file.
      java -XX:-UseGCOverheadLimit -Xms2g -Xmx2g -classpath .:binlogsdk-2.6.0-release.jar LocalDemo
    3. Check the previously configured test.alan.txt file and you can see that data has been pulled into it.
      [root@VM_71_10_centos ~]# cat test.alan.txt  
      Field name: id
      Field type: 3
      Field length: 2
      Field value: 26
      Field name: name
      Field type: 253
      Field length: 4
      Field value: alan

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback