Thrift 小试牛刀

本文介绍了Thrift的基本使用,包括下载版本0.9.3,生成Java代码,实现服务接口,客户端调用以及Transport和Protocol的概念。Transport层提供网络读写的简单抽象,支持如TSocket、TFramedTransport等,而Protocol定义了内存数据结构到网络格式的映射,如TBinaryProtocol和TCompactProtocol。最后,Thrift Server整合这些特性,等待并处理客户端连接。
摘要由CSDN通过智能技术生成


Thrift 官网地址:https://thrift.apache.org/   使用版本 0.9.3


Thrift  0.9.3 下载地址:https://thrift.apache.org/download   下载thrift-0.9.3.tar.gz 和  thrift-0.9.3.exe


Thrift allows developers to define datatypes and service interfaces in a single language-neutral file and generate all the necessary code to build RPC clients and servers.



Hello.thrift 文件:

namespace java  service.demo 
 service Hello{ 
  string helloString(1:string para) 
  i32 helloInt(1:i32 para) 
  bool helloBoolean(1:bool para) 
  void helloVoid() 
  string helloNull() 
 }


切换到thrift-0.9.3.exe 所在目录。执行如下命令:
thrift-0.9.3 --gen java Hello.thrift

会在gen-java 目录下面生成Hello.java文件。

建立maven项目,添加libthrift 依赖。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值