You can use Thrift to enable multi-language access to ApsaraDB for HBase Performance-enhanced Edition clusters.

Prerequisites

The endpoint of your cluster is obtained. For more information, see View cluster endpoints.

Background information

  • The Thrift 1 interface does not support permission authentication. It supports a maximum of 1,000 connections per core node.
  • Thrift 2 allows you to access ApsaraDB for HBase Performance-enhanced Edition clusters only by using HTTPClient. You must specify the username and the password.
  • For more information about how to use Thrift, see the official documentation of Apache Thrift.

Procedure

  1. Download the Thrift installation package.
    Note Some programming languages provide methods to manage dependencies. You can install Thrift based on these programming languages. For example, you can run the pip install thrift command to install Thrift for Python, or directly add import {"github.com/apache/thrift/lib/go/thrift"} to the Go code.
  2. Download the Thrift 2 definition file of ApsaraDB for HBase.
  3. Generate the interface definition file for the specified programming language.
    1. Decompress the thrift-0.12.0.tar package that is downloaded in Step 1. For more information, see Thrift installation guide.
    2. Run a command to open the extracted thrift-0.12.0 file and run the following command to generate an interface definition file:
       thrift --gen <language> Hbase.thrift
      Examples:
      thrift --gen php Hbase.thrift 
      thrift --gen cpp Hbase.thrift 
      thrift --gen py Hbase.thrift 
       q 
       q
  4. Initialize a client to access an ApsaraDB for HBase Performance-enhanced Edition cluster.
    Note
    • The transport layer of the Thrift server for ApsaraDB for HBase Performance-enhanced Edition uses HTTP. Therefore, the ThttpClient in Thrift is required when you initialize the client. If an access control list (ACL) is enabled, two headers must be added to the ThttpClient to transmit the username and the password to the server for authentication.
    • Thrift provides functions that allow you to customize headers in ThttpClients that are developed by using different programming languages.
    The following example shows how to use Python to initialize a client and configure the connection string, the username, and the password.
    # -*- coding: utf-8  -*-
    # Run the pip install thrift command to obtain the following modules:
    from thrift.protocol import TBinaryProtocol
    from thrift.transport import THttpClient
    
    # Run the thrift --gen py hbase.thrift command to generate the following modules:
    from hbase import THBaseService
    from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan
    
    # Configure the connection string.
    url = "http://host:9190"
    transport = THttpClient.THttpClient(url)
    headers = {}
    # Specify the username.
    headers["ACCESSKEYID"]="root";
    # Specify the password.
    headers["ACCESSSIGNATURE"]="root"
    transport.setCustomHeaders(headers)
    protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
    client = THBaseService.Client(protocol)
    transport.open()
    # After you connect to the cluster and perform necessary operations, close the connection.
    transport.close()

References

The demo code for different programming languages is uploaded to GitHub. The code includes the Thrift definition files and the dependencies that are supported by specific programming languages. You can directly download programming language-specific code to initialize clients from GitHub to access ApsaraDB for HBase Performance-enhanced Edition clusters.