Lindorm寬表引擎支援通過HBase非Java(例如C++、Python和Go等)API進行訪問,本文介紹具體的SDK安裝和訪問操作。
背景資訊
Lindorm寬表引擎通過Thrift支援非Java語言(例如C++、Python和Go等)訪問。
Lindorm寬表引擎使用的HBase Thrift2介面定義,所以需要下載HBase Thrift2定義檔案來產生對應語言的介面。與HBase Thrift1定義相比,Lindorm中的HBase Thrift2介面定義更加清晰,您可以獲得和Java語言類似的API調用體驗。目前HBase Thrift2定義檔案比HBase Thrift1定義檔案的功能更全而且更容易使用。
準備工作
已下載Thrift安裝包,下載連結請單擊Thrift安裝包。
已下載HBase Thrift2定義檔案,下載連結請單擊HBase Thrift2定義檔案。
已擷取Lindorm寬表引擎的使用HBase 非Java API訪問的串連地址,具體操作請參見查看串連地址。

訪問Lindorm寬表引擎(以Python語言為例)
Thrift安裝包的使Lindormft官方文檔,通過Thrift訪問雲原生多模資料庫Lindorm寬表引擎的步驟如下:
使用HBase Thrift2定義檔案來產生對應語言的介面檔案。 命令語句如下:
thrift --gen <language> hbase.thrift說明language為目標語言,例如:python、php、cpp、py等。語句樣本:
thrift --gen python hbase.thrift構造用戶端訪問Lindorm寬表引擎。
Lindorm中Thrift伺服器端的transport層使用的是HTTP,因此在構造用戶端時,需要thrift中的ThttpClient(各個語言都有相應實現)。並且在ACL開啟的情況下,需要在ThttpClient上加上兩個header來向伺服器傳輸使用者名稱和密碼進行認證(如果關閉ACL則不需要)。Thrift在每個語言實現的ThttpClient都有加定製header的函數。以Python語言為例,使用以下語句構造用戶端並訪問Lindorm寬表引擎。
# -*- coding: utf-8 -*- # 以下兩個模組通過執行pip install thrift 語句產生 from thrift.protocol import TBinaryProtocol from thrift.transport import THttpClient # 以下兩個模組通過執行thrift --gen py hbase.thrift 語句產生 from hbase import THBaseService from hbase.ttypes import TColumnValue, TColumn, TTableName, TTableDescriptor, TColumnFamilyDescriptor, TNamespaceDescriptor, TGet, TPut, TScan # 配置Lindorm寬表引擎的串連地址 url = "http://ld-bp17j28j2y7pm****-proxy-lindorm.lindorm.rds.aliyuncs.com:9190" transport = THttpClient.THttpClient(url) headers = {} # 設定使用者名稱 headers["ACCESSKEYID"]="testuser"; # 設定使用者名稱對應的密碼 headers["ACCESSSIGNATURE"]="password" transport.setCustomHeaders(headers) protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport) client = THBaseService.Client(protocol) transport.open() # 具體操作後,執行關閉串連操作 transport.close()