百度智能云

All Product Document

          Database Transmission Server

          Brief Introduction of SDK Interfaces

          Introduction

          The data subscription feature of data transmission service (DTS) requires subscription and consumption of incremental data through SDK provided by the service.

          Before consuming with the SDK, you need to create a subscription channel for the source database instance to subscribe to the data transfer console.

          When the subscription channel is created, incremental data in the subscription channel can be subscribed in real-time using SDK.

          At present: Only the SDK of JAVA version is provided for data transmission.

          One subscription channel can only be consumed by one SDK. If multiple SDKs are started to connect to the same subscription channel, the last SDK process started obtains the subscription data, and other SDKs report an error and exit. If there are multiple downstream SDKs, you need to subscribe the incremental data of the same RDS. So, it would be best if you created a subscription channel for each downstream SDK.

          Multiple interfaces and classes are defined in the SDK. The method definitions of these classes and interfaces in the SDK are introduced in this section.

          RegionContext Class Definition

          RegionContext is used to save the meta information required to start the data subscription SDK. This section describes the main interface functions of RegionContext.

          • void setAccessKey(String accessKey)

          Set a security credential, and the parameter is AccessKey of Baidu AI Cloud account corresponding to the subscription task requiring data subscription.

          • void setSecretKey(String secretKey)

          Set a security credential, and the parameter is SecretKey corresponding to Baidu AI Cloud account. You can go to the Security Certification/Access Key page to create and obtain.

          • void setDtsId(String dtsId)

          Request the incremental data of a subscription task, parameter String dtsId is the ID of the subscription task, and you need to obtain it at the data transmission console.

          ConsumerClient Interface Definition

          ConsumerClient is the global management object of data subscription SDK, and the main interface functions of RegionContext are introduced in this section.

          • void start()

            Start the SDK client and start subscribing the incremental data.

          • void stop(boolean is Async)

            Stop the SDK client and stop subscribing the incremental data. The parameter is whether to stop the SDK asynchronously, and true means to return directly without waiting for the SDK internal thread to end.

          • void addConcurrentListener(ConsumerListener arg0)

            Register consumption listener, only the registered ConsumerListener can process the received subscription data.

            Parameter ConsumerListener arg0 is the object of ClusterListener class.

          ConsumerListener interface definition

          ConsumerListener is the consumer listener, used to encapsulate custom consumption and handling exception logics. The main interface functions of ConsumerListener are introduced in this section.

          • void notify(DataMessage dataMsg)

            Consumption logic used to define subscription data. When SDK receives the data, it does notify the ConsumerListener to consume the data through Notify.

            The input parameter type of function is DataMessage. See DataMessage interface definition for specific definition.

          • void noException(Exception paramException)

            It is mainly used to define the handling method of exception encountered when executing the notify function.

            The function input parameter type is: Exception, i.e., the exception object thrown during execution.

          DataMessage class definition

          Each DataMessage saves several change data records in the source database instance, and each record is saved through Record. The main interface functions of DataMessage are introduced in this section.

          • List getRecordList()

            It is used to obtain a list of Record objects saved in DataMessage.

          Record class definition

          The Record represents a single change record of the subscribed source database instance. The main interface functions of Record are introduced in this section.

          • byte[] getDbName()

            The library name used to return the change record.

          • byte[] getTblName()

            The table name used to return the change record.

          • RecordType getRecordType()

            The change type used to return the change record.

            The change types include INSERT, UPDATE, DELETE, BEGIN, COMMIT, and DDL.

          • String getPosition()

            binlog position used to return the change record.

          • String getOffset()

            Used to return the offset of the change record in the internal cache (disabled).

          • String getTimestamp()

            The time stamp used to return the change record.

          • List getFields()

            The field list used to return the change record.

            List contains the definitions of all fields in the corresponding table of this change record and the image values before and after the change. For the definition of Field object, see the definition of field interface.

          • byte[] getDdl()

            When the change record type is DDL, DDL SQL of statement format is returned. Otherwise, it is null.

          Field class definition

          The Field defines the code, type, field name, field value, and other attributes of each field. Each interface definition of the Field class is introduced in this section.

          • byte[] getFieldName()

            It is used to return the field name.

          • String getFieldType()

            It is used to return the field type.

          • String getFieldCharset()

            It is used to return the field character set.

          • byte[] getValueBefore()

          It is used to return the value of this field before change. This field is null for INSERT type and non-DML type.

          • byte[] getValueAfter()

            It is used to return the value of this field after change. This field is null for DELETE type and non-DML type.

          Previous
          SDK Download Page
          Next
          SDK Download