node.js - 从 NodeJS 连接到 Accumulo

标签 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'}

请参阅下面的答案。

最佳答案

事实证明,问题的存在是因为处理了从 Accumulo 返回的响应。在 AccumuloProxy.js 文件中,当接收到登录结果并在 AccumuloProxy_login_result.prototype.read 中读取时,它将成功设置为 this.success = input.readString()

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

我修改了 AccumuloProxy_login_result.prototype.read 函数以将成功设置为 this.success = input.readBinary() 以便 Buffer被退回。此 Buffer 可以传递给其他函数调用,并将从 Accumulo 返回正确的结果而不是异常。

这是 Thrift 的一个问题 here并且显然已在 master 分支中修复。

关于node.js - 从 NodeJS 连接到 Accumulo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21684165/

相关文章:

javascript - ^ Node 脚本参数中的字符

javascript - 无法读取未定义的属性 "..."

node.js - 在 Azure SQL 上续写 "Connection closed"

json - Thrift、JSON 和 REST 之间的区别

python - Thrift python 3.4 TypeError : string argument expected, 得到 'bytes'

java - 找不到 org.apache.thrift7.TBase 类

node.js - 从测试文件 Compound.js 中读取环境特定变量

scala - 使用 finagle 进行持久身份验证

c# - 节俭.Transport.TTransportException : Cannot write to null outputstream

thrift - 一个 thrift 服务器/传输可以实现多个服务吗?