顺便说一下windows下的安装,直接下载http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.1/thrift-0.9.1.exe
重命名thrift-0.9.1.exe为thrift.exe,然后拷贝到C:\Windows下即可。
打开cmd:
C:\Users\hanqunfeng>thrift -version Thrift version 0.9.1
代码生成: thrift --gen <language> <Thrift filename>
比如:
java:thrift --gen java hello.thrift
python:thrift --gen py hello.thrift
结构文件定义:
#包
namespace java thrift.service
namespace py thrift.service
#类
struct Book{
1:i32 id
2:string name
}
struct Contact{
1:i32 id
2:string name
3:i64 birthday
4:string phoneNo
5:string ipAddress
6:map<string,string> props
7:double salary
8:set<Book> books
}
#接口服务
service ContactManager{
void save(1:Contact contact)
void remove(1:i32 id)
list<Contact> getAll();
list<Contact> query(1:map<string,string> conditions)
}
下载:http://thrift.apache.org/download/
安装:http://thrift.apache.org/docs/BuildingFromSource/
依赖:http://thrift.apache.org/docs/install/
sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
基本上如下命令即可:
./configure
make
make install
参考教程:
http://wenku.baidu.com/view/b36c26d13186bceb19e8bbb4.html
http://www.open-open.com/doc/view/f08c1868010b4eef94a91b2b9bd31417