tencent cloud


Database/Table Data Subscription to Local File System

Last updated: 2021-01-06 10:04:08

    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 to go to 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 LocalDemo.java file.

      // 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 sync 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. javac -classpath binlogsdk-2.6.0-release.jar -encoding UTF-8 LocalDemo.java
    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
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support