使用节俭nodejs连接hbase时拒绝连接

sqxo8psd  于 2021-06-09  发布在  Hbase
关注(0)|答案(2)|浏览(559)

我想在hbase中保存数据。所以我想连接nodejs和hbase。我找到了一本教程http://www.amicksolutions.com/blog/hadoop-using-nodejs-with-hbase 以及它的工作原理。以下是hbase连接的代码:

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);
});

这上面的代码是完美的工作,我能够列出所有的表,但问题是我想做凝乳操作也。我已经搜索了很多,但没有找到关于这个模块的正确文档,如何做其他操作,如get,put。
这是我找到的另一个模块https://github.com/wdavidw/node-hbase 有良好的文档,但我无法连接以下代码:

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);
      });
    });
  });
})

这可能是我必须使用一些协议在这里也。我不知道这是什么。我无法连接,出现以下错误:

{ [Error: connect ECONNREFUSED]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect' }

另一个困惑是https://github.com/wdavidw/node-hbase 此模块是否使用thrift api?还有其他解决办法吗?

dvtswwa3

dvtswwa31#

我就是这样做的:

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);
}
q5lcpyga

q5lcpyga2#

我在尝试连接节点hbase时遇到了相同的错误:

{ 
    [Error: connect ECONNREFUSED]
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect' 
}

我的解决方案基于hbase.apache.org的书,章节:rest。在hbase目录中的hbase服务器上(对我来说是 /usr/local/hbase/ ,只是为了更好的概述),我跑了:

./bin/hbase rest start -p 8080

它启动rest服务器,端口 8080 是默认值,请根据需要进行调整。之后,运行node hbase文档中的代码:

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);
      });
    });
  });
})

工作如期进行。

相关问题