Thrift 的学习笔记
??? 最近做的项目是使用CXF编写Service,给公司的其他项目提供接口的。由于需求问题,改用Thrift。下面就总结下自己学习Apache Thrift的内容,和例子。
1. 下载thrift-0.9.0.exe 。我使用的是win7系统,将该文件复制到C盘Windows下,并改名thrift.exe方便执行命令。运行cmd.exe。输入命令
public class ThriftClient{ public static void main(String[] args){ TTransport transport = new TSocket("localhost", 9090); TProtocol protocol = new TBinaryProtocol(transport); TestService.Client cient = new TestService.Client(protocol); try{ transport.open(); String str = client.getUsername(10); System.out.println(str); } catch(TException e){ e.printStackTrace(); } finally { transport.close(); } }}?6.执行ThriftServer文件,启动服务
?
7.执行ThriftClient文件,测试