从NodeJS连接到Accumulo

时间:2014-02-10 17:37:49

标签: node.js thrift thrift-protocol accumulo

我一直试图通过Thrift代理从NodeJS连接到Accumulo,但一直没有成功。

var thrift = require("thrift");
var AccumuloClient = require("./AccumuloProxy");

var transport = thrift.TFramedTransport;
var protocol = thrift.TBinaryProtocol;

var connection = thrift.createConnection("localhost", 42424, {
    transport: transport,
    protocol: protocol
});

var client = thrift.createClient(AccumuloClient, connection);

client.login("root", {'password': "password"});

当我尝试登录时,我得到了

org.apache.thrift.protocol.TProtocolException: Expected protocol id ffffff82 but got ffffff80

有人能帮助我,让我知道我在这里做错了吗?

<小时/> 的更新:

我修改了位于Accumulo的proxy.properties文件中的protocolFactory行并重新启动了代理。

protocolFactory=org.apache.thrift.protocol.TBinaryProtocol$Factory

我执行了与上面相同的步骤,但添加了对createClient来电的回调。

var login;
var client = thrift.createClient(AccumuloClient, connection, 
    function(err, success) { login = success });

这会填充登录变量。然后我尝试使用该登录变量来执行其他功能

client.listTables(login, function(a) { console.log(a) })

结果

{name: 'TApplicationException', 
 type: 6,
 message: 'Internal error processing listTables'}

尝试创建表

client.createTable(login, "testTable", 1, "", function(a) { console.log(a)})

结果

{name: 'AccumuloSecurityException',
 msg: 'org.apache.accumulo.core.client.AccumuloSecurityException: Error SERIALIZATION_ERROR for user unknown - Unknown security exception'}

见下面的答案。

2 个答案:

答案 0 :(得分:2)

事实证明,由于处理来自Accumulo的回复而存在问题。在AccumuloProxy.js文件中,当收到登录结果并在AccumuloProxy_login_result.prototype.read中读取时,它会将成功设置为this.success = input.readString()

readString()函数将使用Buffer并使用toString()编码调用utf8。这导致字符显示不正确。

我修改了AccumuloProxy_login_result.prototype.read函数以将成功设置为this.success = input.readBinary(),以便返回Buffer。这个Buffer可以传入其他函数调用,并从Accumulo而不是Exception获得正确的结果。

这是Thrift here的一个问题,显然已在主分支中修复。

答案 1 :(得分:0)

似乎Accumulo使用compact协议,而不是binary协议。看来,NodeJS目前还没有紧凑的协议支持。

请同时查看this SO question。它处理C#,但它可能会有所帮助。还有一些解决方案利用RabbitMQ或其他消息代理see here

相关问题