Develop applications using the HBase non-Java API
The Lindorm Lindorm wide table engine supports access through HBase APIs for non-Java languages such as C++, Python, and Go. This topic describes how to connect.
Prerequisites
-
You have downloaded the Thrift installation package.
-
You have downloaded the HBase Thrift2 definition file.
-
You have obtained the Access by Using HBase non-Java API endpoint for the Lindorm wide table engine. For more information, see View endpoints. Sign in to the Lindorm console. On the instance details page, select the Wide Table Engine tab. Expand the HBase-compatible Endpoints section. Then obtain the VPC or public endpoint in the HBase non-Java API section. The port number is 90.
Connect to the Lindorm wide table engine using the HBase non-Java API (Python example)
For information about using Thrift, see the Apache Thrift official documentation. Use Thrift to access the Lindorm wide table engine as follows:
-
Use the HBase Thrift2 definition file to generate the interface files for your target language. Run the following command:
thrift --gen <language> Hbase.thriftNoteThe
languageplaceholder represents your target programming language, for example, python, php, cpp, or py.Sample statement:
thrift --gen py Hbase.thrift -
Create a client to access the Lindorm wide table engine.
The Thrift server in Lindorm uses HTTP for transport, so create the client with the THttpClient implementation provided by Thrift. Each language provides its own implementation. If ACL is enabled, add two headers to THttpClient to send the username and password to the server for authentication. These headers are not required if ACL is disabled. Each language implementation of THttpClient provides a function for setting custom headers. The following Python example shows how to create a client and connect to the Lindorm wide table engine:
# -*- coding: utf-8 -*- # The following two modules are generated by running the 'pip install thrift' command. from thrift.protocol import TBinaryProtocol from thrift.transport import THttpClient # The following two modules are generated by running the 'thrift --gen py hbase.thrift' command. from hbase import THBaseService from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan # Configure the endpoint for the Lindorm wide table engine. url = "http://ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com:9190" transport = THttpClient.THttpClient(url) headers = {} # Set the username. headers["ACCESSKEYID"]="testuser"; # Set 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 after the operations are complete. transport.close()