NodeJS:thrift vs thrift-http包 - 使用哪一个?

时间:2016-01-21 18:39:29

标签: node.js thrift

在NodeJS上使用thrift的这两个包之间有什么区别:
- thrift
- thrift-http
乍一看,使用thrift-http而不是thrift时需要http,但我安装了thrift包,并且确实在其中定义了createHttpConnection方法。这是我写的示例代码:

var thrift = require('thrift');
var myService = require('./gen-nodejs/MyService');
var transport = thrift.TBufferedTransport;
var protocol = thrift.TBinaryProtocol;
// connect to proxy on 127.0.0.1:8888
var connection = thrift.createHttpConnection('127.0.0.1', 8888, {
  transport : transport,
  protocol : protocol,
  path: 'http://localhost:5331/myhandler',  
});

connection.on('error', function(err) {
    console.log(err);
});

// Create a client with the connection
var client = thrift.createHttpClient(myService, connection);
console.log('calling getTotalJobCount...');

client.getTotalJobCount(function(count)
{
    console.log('total job count = ' + count);
});

但是当我运行它时,我得到了这个:

total job count = NULL

这不是预期的,因为服务返回一个在客户端回调中不能显示为NULL的整数。我现在无法找到该链接,但是昨天我在某个地方读到了thrift只支持TJSONProtocol而不是http。即使现在这是正确的吗?这就是我看到NULL的原因吗?另外在哪里可以看到nodejs中thrift的源代码? This是Google在搜索" thrift nodejs"时出现的第一个链接。似乎代码完全过时了。

1 个答案:

答案 0 :(得分:0)

thrift软件包是Apache Thrift项目团队提供的软件包。

另一个是别人的包裹,与任何方式的“官方”来源无关。在对相关提交进行快速检查之后,文件的版本似乎也是0.9.3,这是最新的正式版本。但是,我不能说所有这些文件是完全原创的,还是已被修改过。你必须自己验证(或者只相信那个人)。