All Products
Search
Document Center

ApsaraDB for HBase:Use the multi-language API to access ApsaraDB for HBase Performance-enhanced Edition clusters

Last Updated:Mar 19, 2024

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 Apply for a public endpoint.

Background information

  • The Thrift 1 interface does not support 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 an interface definition file for the specified programming language.

    1. Decompress the thrift-0.12.0.tar.gz package that is downloaded in Step 1. For more information, see Thrift installation guide.

    2. In the command line interface (CLI), 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
  4. Initialize a client to access an ApsaraDB for HBase Performance-enhanced Edition cluster.

    Note
    • HTTP is used at the transport layer of the Thrift server for ApsaraDB for HBase Performance-enhanced Edition. Therefore, the ThttpClient in Thrift is required when you initialize the client. If an access control list (ACL) is enabled, you must add two headers to the ThttpClient to transmit the username and the password to the server for authentication.

    • Thrift allows you to call a function for a language to specify a custom header in ThttpClient.

    The following example shows how to use Python to initialize a client and configure the connection string, username, and password.

    # -*- coding: utf-8  -*-
    # You can run the pip install thrift command to retrieve the following modules.
    from thrift.protocol import TBinaryProtocol
    from thrift.transport import THttpClient
    
    # The following module is generated by the thrift --gen py hbase.thrift command.
    from hbase import THBaseService
    from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan
    
    # The endpoint.
    url = "http://host:9190"
    transport = THttpClient.THttpClient(url)
    headers = {}
    # The username.
    headers["ACCESSKEYID"]="testuser";
    # The password.
    headers["ACCESSSIGNATURE"]="password"
    transport.setCustomHeaders(headers)
    protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
    client = THBaseService.Client(protocol)
    transport.open()
    # The operations. The connection is finally closed.
    transport.close()

Related resources

The demo code for different programming languages is uploaded to GitHub. The code includes the Thrift definition files and the dependent libraries 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.

For more information, see Apache Thrift Tutorial.