首页 > 其他 > 详细

Node 与 Thrift

时间:2015-04-16 22:03:07      阅读:293      评论:0      收藏:0      [点我收藏+]

 背景:公司要用Node与其他语言(Java)写的服务通信。


1,服务端 helloServer.js

var thrift = require(‘thrift‘);
var helloService = require(‘./HelloService‘);
var server = thrift.createServer(helloService, {
    hello: function(para, success){
        console.log("para: " + para);
        success(null, "Hi, Client! I am Server!");
    }
}, {});
server.listen(8080);


2,客户端 helloClient.js

var thrift = require(‘thrift‘);
var helloService = require(‘./HelloService‘);
//创建连接和客户端
var connection = thrift.createConnection(‘localhost‘, 8080);
connection.on(‘error‘, function(err) {
    console.error(err);
});
var client = thrift.createClient(helloService, connection);
//调用hello方法
var para = ‘Hi Server! I am Client.‘;
client.hello(para, function(err, res){
    if(err){
        console.error("Error: " + err);
    }else{
        console.log("Result: " + res);
    }
    connection.end();
});

3,thrift compiler version: 0.9.2.
 

4,此版本的node第三方库thrift的server.js文件有个bug,导致thrift.createServer(processor, handler, options)的第三个参数必须得传。

 技术分享
截图红框中的代码应该为:

if (options && options.tls) {


技术分享

Node 与 Thrift

原文:http://my.oschina.net/aaxaac/blog/402585

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!