Node Hbase connection error
I want to store my data in Hbase. So I wanted to connect to Nodejs and Hbase. I found the tutorial http://www.amicksolutions.com/blog/hadoop-using-nodejs-with-hbase and it works. This is the following Hbase connection code:
var thrift = require('thrift'),
HBase = require('./gen-nodejs/HBase.js'),
HBaseTypes = require('./gen-nodejs/HBase_types.js'),
connection = thrift.createConnection('localhost', 9090, {
transport: thrift.TBufferedTransport,
protocol: thrift.TBinaryProtocol
});
connection.on('connect', function() {
var client = thrift.createClient(HBase,connection);
client.getTableNames(function(err,data) {
if (err) {
console.log('get table names error:', err);
} else {
console.log('hbase tables:', data);
}
connection.end();
});
});
connection.on('error', function(err){
console.log('error:', err);
});
This above code works fine, I can list all tables, but the problem is I want to do CURD operations too. I searched a lot but could not find the correct documentation for this module. How to do other operations like get, put.
This is another module that I found https://github.com/wdavidw/node-hbase Having good documentation but I cannot link with this following code:
var assert = require('assert');
var hbase = require('hbase');
hbase({ host: '127.0.0.1', port: 9090 })
.table('my_table' )
.create('my_column_family', function(err, success){
this
.row('my_row')
.put('my_column_family:my_column', 'my value', function(err, success){
this.get('my_column_family', function(err, cells){
this.exists(function(err, exists){
assert.ok(exists);
});
});
});
})
I may also have to use some kind of protocol. I don't know what the catch is. I cannot connect and receive the following error:
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
Another confusion https://github.com/wdavidw/node-hbase does this module use the trift API or not? Is there any other workaround?
source to share
This is how I did the insert:
try{
var data = [];
data.push(new Mutation({column:'data:sender','value':'2444'}));
data.push(new Mutation({column:'data:receiver','value':'1334'}));
data.push(new Mutation({column:'data:message','value':'HIdfgs'}));
var client = thrift.createClient(HBase,connection);
// console.log(client.mutateRow)
client.mutateRow(TABLE, 'row1', data, null, function(error, success){
console.log("INsertklsd")
})
} catch(e) {
console.log(e);
}
source to share
I had the same error when I tried to connect to node-hbase :
{
[Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect'
}
My solution was based on the hbase.apache.org book, chapter: REST . On your hbase server in the hbase directory (for me this is /usr/local/hbase/
, just for a better overview), I ran:
./bin/hbase rest start -p 8080
It starts the REST server, the port 8080
is default, customize it for your needs. After that, run the code from the node-hbase documentation :
var assert = require('assert');
var hbase = require('hbase');
hbase({ host: '127.0.0.1', port: 8080})
.table('my_table' )
.create('my_column_family', function(err, success){
this
.row('my_row')
.put('my_column_family:my_column', 'my value', function(err, success){
this.get('my_column_family', function(err, cells){
this.exists(function(err, exists){
assert.ok(exists);
});
});
});
})
worked properly.
source to share