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
Download the Thrift installation package.
NoteSome 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 addimport {"github.com/apache/thrift/lib/go/thrift"}
to the Go code.Download the Thrift 2 definition file of ApsaraDB for HBase.
Generate an interface definition file for the specified programming language.
Decompress the
thrift-0.12.0.tar.gz
package that is downloaded in Step 1. For more information, see Thrift installation guide.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
Initialize a client to access an ApsaraDB for HBase Performance-enhanced Edition cluster.
NoteHTTP 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.
Python: Download the sample code.
C++: Download the sample code.
Node.js: Download the sample code.
PHP: Download the sample code.
For more information, see Apache Thrift Tutorial.