码迷,mamicode.com
首页 > 其他好文 > 详细

Node 与 Thrift

时间:2015-04-16 22:05:43      阅读:143      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!