All Products
Search
Document Center

Lindorm:Use the ApsaraDB for HBase API for a non-Java language to develop applications

Last Updated:Aug 24, 2023

This topic describes how to use the ApsaraDB for HBase API for a non-Java language, such as C++, Python, and Go, to connect to and use LindormTable.

Prerequisites

Use the ApsaraDB for HBase API for a non-Java language, such as Python, to connect to LindormTable

For more information about how to install Thrift by using the Thrift installation package, see the Apache Thrift official documentation. You can perform the following steps to use Thrift to connect to LindormTable:

  1. Execute the following statement to use the Thrift2 definition file for ApsaraDB for HBase to generate an interface definition language (IDL) file in the corresponding language:

    thrift --gen <language> Hbase.thrift
    Note

    The language parameter specifies the programming language that you want to use. You can set this parameter to python, php, cpp, or py.

    Sample statement:

    thrift --gen python Hbase.thrift
  2. Create a client to connect to LindormTable.

    The Thrift server in Lindorm uses HTTP in the transport layer. The ThttpClient of Thrift is required when you create a client. The method of creating the client varies based on the languages. If the Access Control List (ACL) is enabled, specify the username and password in two headers in the ThttpClient for authentication. The username and password are not required if ACL is disabled. Thrift allows you to call a function for a language to specify a custom header in ThttpClient. In the following example, Python is used. You can execute the following statements to create a client and connect to LindormTable:

     # -*- coding: utf-8  -*-
     # You can run the pip install thrift command to generate the following two modules:
     from thrift.protocol import TBinaryProtocol
     from thrift.transport import THttpClient
    
     # You can run the thrift --gen py hbase.thrift command to generate the following two modules:
     from hbase import THBaseService
     from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan
    
     # Specify the endpoint of LindormTable.
     url = "http://ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com:9190"
     transport = THttpClient.THttpClient(url)
     headers = {}
     # Specify the username.
     headers["ACCESSKEYID"]="testuser";
     # Specify the password that corresponds to the username.
     headers["ACCESSSIGNATURE"]="password"
     transport.setCustomHeaders(headers)
     protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
     client = THBaseService.Client(protocol)
     transport.open()
     # Close the connection.
     transport.close()

Sample code in other languages

To obtain complete sample code for other non-Java languages, click one of the following download links to download sample code for a language from GitHub: