Access HBase using NodeJS and Thriftt [Scalable Cross-language Service Development Software Framework]. Due to a poor understanding of thrift at first, gen-nodejs files were never generated correctly.
This article records the correct solution of NodeJS accessing HBase through thrift on a Window.
First step, install thrift
1.1 download
Open the thrift’s official website to download address: http://thrift.apache.org/download
Select the second. Exe file [red box] and download it.
The downloaded file is an executable called thrift-0.11.0.exe.
1.2 Rename and change the storage path
Rename the file thrift. Exe, which I did for convenience.
Then place the renamed file in a directory in the Window. I put the file in D:\soft\ Thrift\
1.3 Configuring Environment Variables
Let’s go straight to the picture above
1.4 Verifying the installation
Type thrift -version and the installation is successful!
2 Generate the Thrift NodeJS interface file
http://thrift.apache.org/ “website address”
It took a long time to wrestle with the second step of the red label on the website. Does Windows need to create a Compiler and install it?
Do I need to write a.thrift file? Current Hbase (0.11.0, on which this article is based) has two sets of thrift interfaces (you can call thrift1 and ThrifT2), which are incompatible (too arbitrary, which is probably a problem with all open source software). Since the ThrifT2 interface is designed to be more elegant than Thrfit’s, or more closely aligned with the current API, Thrift1 is likely to be phased out.
Git thrift2 address: https://github.com/apache/hbase/blob/master/hbase-thrift/src/main
/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift
Download the project and place hbase.thrift in the project folder with the CMD command line in the project
Run thrift –gen JS :node hbase.thrift
The directory contains the additional folder gen-nodejs, which contains the two files shown in the figure.
Almost done.
3. How to develop and connect?
Here is a simple example
const thrift = require('thrift');
const HBase = require('.. /hbases/gen-nodejs/THBaseService');
exports.hbase= { connection: () => { let options = { hb: {native_parser: true}, server: { poolSize: 6, connectTimeoutMS: 30000, socketOptions: {keepAlive: 120}, reconnectTries: Number.MAX_VALUE }, replset: { rs_name: 'rs0', socketOptions: {keepAlive: 120} }, transport: thrift.TBufferedTransport, protocol: thrift.TBinaryProtocol }; return thrift.createConnection('127.0.0.1'.'9090', options); }, connect () { this.connection() .on('connect', () => {
console.info('hbase hb connected.'); letclient = thrift.createClient(HBase, this.connection()) // .... }).on()'close', () => { console.info('HB is closed'); }) .on('error', (err) => { console.debug('error '+err.message); }); }};Copy the code